#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

const int MAX_BOOKS = 10;
const int LATE_FEE = 10;
const int FREE_DAYS = 14;

string titles[MAX_BOOKS];
bool available[MAX_BOOKS];
int bookCount = 0;

void addBook() {
    if (bookCount >= MAX_BOOKS) {
        cout << "Library catalog is full. Cannot add more books.\n";
        return;
    }

    string title;
    cout << "Enter the title of the book to add: ";
    cin.ignore();
    getline(cin, title);

    titles[bookCount] = title;
    available[bookCount] = true;

    bookCount++;

    cout << "Book added with number " << bookCount << ".\n";
}

void borrowBook() {
    if (bookCount == 0) {
        cout << "No books available in the catalog.\n";
        return;
    }

    int num;
    cout << "Enter the number of the book to borrow: ";
    cin >> num;

    if (num < 1 || num > bookCount) {
        cout << "Invalid book number.\n";
        return;
    }

    if (!available[num - 1]) {
        cout << "The book is already borrowed.\n";
        return;
    }

    available[num - 1] = false;

    cout << "You have successfully borrowed \""
         << titles[num - 1] << "\".\n";
}

void returnBook() {
    int num, days;

    cout << "Enter the number of the book to return: ";
    cin >> num;

    if (num < 1 || num > bookCount) {
        cout << "Invalid book number.\n";
        return;
    }

    if (available[num - 1]) {
        cout << "This book was not borrowed.\n";
        return;
    }

    cout << "How many days was the book borrowed? ";
    cin >> days;

    if (days < 0) {
        cout << "Invalid number of days.\n";
        return;
    }

    available[num - 1] = true;

    if (days > FREE_DAYS) {
        int penalty = (days - FREE_DAYS) * LATE_FEE;

        cout << fixed << setprecision(2);
        cout << "Late return penalty: Php "
             << penalty << ".\n";
    } else {
        cout << "Thank you for returning the book on time.\n";
    }
}

void viewAllBooks() {
    if (bookCount == 0) {
        cout << "No books in the catalog.\n";
        return;
    }

    cout << "\n--- Library Book Catalog ---\n";

    for (int i = 0; i < bookCount; i++) {
        cout << "Book " << i + 1 << ": "
             << titles[i] << " - ";

        if (available[i]) {
            cout << "Available\n";
        } else {
            cout << "Borrowed\n";
        }
    }
}

void viewBorrowedBooks() {
    bool found = false;

    cout << "\n--- Borrowed Books ---\n";

    for (int i = 0; i < bookCount; i++) {
        if (!available[i]) {
            cout << "Book " << i + 1 << ": "
                 << titles[i] << "\n";
            found = true;
        }
    }

    if (!found) {
        cout << "No books are currently borrowed.\n";
    }
}

int main() {
    int choice;

    do {
        cout << "\n--- Library Management System ---\n";
        cout << "1. Add a Book\n";
        cout << "2. Borrow a Book\n";
        cout << "3. Return a Book\n";
        cout << "4. View All Books\n";
        cout << "5. View Borrowed Books\n";
        cout << "6. Exit\n";
        cout << "Select an option: ";
        cin >> choice;

        switch (choice) {
            case 1:
                addBook();
                break;

            case 2:
                borrowBook();
                break;

            case 3:
                returnBook();
                break;

            case 4:
                viewAllBooks();
                break;

            case 5:
                viewBorrowedBooks();
                break;

            case 6:
                cout << "Exiting the Library Management System. Goodbye!\n";
                break;

            default:
                cout << "Invalid option. Please try again.\n";
        }

    } while (choice != 6);

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: