Untitled

 avatar
unknown
c_cpp
a year ago
7.1 kB
4
Indexable
#include <iostream>
#include <string>
#include <vector>

using namespace std;

// Base class representing a user
class User {
protected:
    string name;            // User's name
    string username;        // User's username
    string password;        // User's password
    string phoneNumber;     // User's phone number
    string emailAddress;    // User's email address
    string role;            // User's role (e.g., librarian, patron, etc.)

public:
    // Constructor to initialize user data
    User(string n, string u, string p, string pn, string e, string r)
        : name(n), username(u), password(p), phoneNumber(pn), emailAddress(e), role(r) {}

    // Method to authenticate user login
    bool login(string enteredUsername, string enteredPassword) {
        if (enteredUsername == username && enteredPassword == password) {
            cout << "Login successful." << endl;
            return true;
        } else {
            cout << "Login failed. Invalid username or password." << endl;
            return false;
        }
    }

    // Method to logout user
    void logout() {
        cout << "Logged out successfully." << endl;
    }

    // Method to change user password
    void changePassword(string newPassword) {
        password = newPassword;
        cout << "Password changed successfully." << endl;
    }
};

// Class representing a book
class Book {
private:
    string title;           // Book's title
    string author;          // Book's author
    string genre;           // Book's genre
    int numberOfCopies;     // Number of copies available

public:
    // Constructor to initialize book data
    Book(string t, string a, string g, int nc) : title(t), author(a), genre(g), numberOfCopies(nc) {}

    // Method to check out a book
    void checkOut() {
        if (numberOfCopies > 0) {
            numberOfCopies--;
            cout << "Book checked out successfully." << endl;
        } else {
            cout << "Sorry, the book is not available for checkout." << endl;
        }
    }

    // Method to check in a book
    void checkIn() {
        numberOfCopies++;
        cout << "Book checked in successfully." << endl;
    }

    // Method to renew a book
    void renew() {
        cout << "Book renewed successfully." << endl;
    }

    // Method to check if the book is available
    bool isAvailable() {
        return numberOfCopies > 0;
    }

    // Getters for book attributes
    string getTitle() const {
        return title;
    }

    string getAuthor() const {
        return author;
    }

    string getGenre() const {
        return genre;
    }

    int getNumberOfCopies() const {
        return numberOfCopies;
    }
};

// Class representing a magazine
class Magazine {
private:
    string title;               // Magazine's title
    string publisher;           // Magazine's publisher
    string publicationDate;     // Magazine's publication date

public:
    // Constructor to initialize magazine data
    Magazine(string t, string pub, string pubDate) : title(t), publisher(pub), publicationDate(pubDate) {}

    // Method to check out a magazine
    void checkOut() {
        cout << "Magazine checked out successfully." << endl;
    }

    // Method to check in a magazine
    void checkIn() {
        cout << "Magazine checked in successfully." << endl;
    }

    // Method to check if the magazine is available
    bool isAvailable() {
        return true;
    }

    // Getters for magazine attributes
    string getTitle() const {
        return title;
    }

    string getPublisher() const {
        return publisher;
    }

    string getPublicationDate() const {
        return publicationDate;
    }
};

// Class representing a library patron
class Patron : public User {
private:
    int libraryCardNumber;      // Patron's library card number
    string address;             // Patron's address

public:
    // Constructor to initialize patron data
    Patron(string n, string u, string p, string pn, string e, string r, int lcn, string addr)
        : User(n, u, p, pn, e, r), libraryCardNumber(lcn), address(addr) {}

    // Method to register patron account
    void registerAccount() {
        cout << "Patron account registered successfully." << endl;
    }

    // Methods to interact with books and magazines
    void checkoutBook(Book &book) {
        book.checkOut();
    }

    void checkoutMagazine(Magazine &magazine) {
        magazine.checkOut();
    }

    void checkInBook(Book &book) {
        book.checkIn();
    }

    void checkInMagazine(Magazine &magazine) {
        magazine.checkIn();
    }

    void renewBook(Book &book) {
        book.renew();
    }

    void renewMagazine(Magazine &magazine) {
        cout << "Magazine renewed successfully." << endl;
    }

    void viewCheckedOutMaterials() {
        cout << "List of checked out materials:" << endl;
        // Logic to display checked out materials
    }

    // Getters for patron attributes
    int getLibraryCardNumber() const {
        return libraryCardNumber;
    }

    string getAddress() const {
        return address;
    }
};

// Class representing a librarian
class Librarian : public User {
private:
    int employeeId;             // Librarian's employee ID
    string department;          // Librarian's department

public:
    // Constructor to initialize librarian data
    Librarian(string n, string u, string p, string pn, string e, string r, int empId, string dept)
        : User(n, u, p, pn, e, r), employeeId(empId), department(dept) {}

    // Methods to manage books and magazines
    void addBook(Book &book) {
        cout << "Book added successfully." << endl;
    }

    void editBook(Book &book) {
        cout << "Book edited successfully." << endl;
    }

    void deleteBook(Book &book) {
        cout << "Book deleted successfully." << endl;
    }

    void addMagazine(Magazine &magazine) {
        cout << "Magazine added successfully." << endl;
    }

    void editMagazine(Magazine &magazine) {
        cout << "Magazine edited successfully." << endl;
    }

    void deleteMagazine(Magazine &magazine) {
        cout << "Magazine deleted successfully." << endl;
    }

    // Getters for librarian attributes
    int getEmployeeId() const {
        return employeeId;
    }

    string getDepartment() const {
        return department;
    }
};

int main() {
    // Example usage
    Book book1("The Great Gatsby", "F. Scott Fitzgerald", "Fiction", 5);
    Magazine magazine1("National Geographic", "National Geographic Society", "March 2024");

    Patron patron("John Doe", "johndoe", "password", "123456789", "johndoe@example.com", "patron", 123456, "123 Main St.");
    Librarian librarian("Jane Smith", "janesmith", "password", "987654321", "janesmith@example.com", "librarian", 987654, "Library Department");

    // ...

    return 0;
}
Editor is loading...
Leave a Comment