Untitled

mail@pastecode.io avatar
unknown
plain_text
20 days ago
4.8 kB
7
Indexable
Never
#ifndef BOOK_H
#define BOOK_H

#include <string>

class Book {
private:
    int id;
    std::string name;
    std::string author;
    double cost;
    std::string status;

public:
    // Constructor
    Book(int bookId, const std::string& bookName, const std::string& bookAuthor, double bookCost);

    // Getters
    int getId() const;
    std::string getName() const;
    std::string getAuthor() const;
    double getCost() const;
    std::string getStatus() const;

    // Setters
    void setId(int bookId);
    void setName(const std::string& bookName);
    void setAuthor(const std::string& bookAuthor);
    void setCost(double bookCost);
    void setStatus(const std::string& bookStatus);

    // Methods
    virtual void lend();
    virtual void returnBook();
    virtual void lost();
};

class EncyclopediaBook : public Book {
private:
    std::string type;
    std::string publisher;

public:
    EncyclopediaBook(int bookId, const std::string& bookName, const std::string& bookAuthor, double bookCost, const std::string& bookType, const std::string& bookPublisher);
    std::string getType() const;
    std::string getPublisher() const;
    void setType(const std::string& bookType);
    void setPublisher(const std::string& bookPublisher);
    void refer();
};

class FictionBook : public Book {
private:
    std::string type;
    std::string region;

public:
    FictionBook(int bookId, const std::string& bookName, const std::string& bookAuthor, double bookCost, const std::string& bookType, const std::string& bookRegion);
    std::string getType() const;
    std::string getRegion() const;
    void setType(const std::string& bookType);
    void setRegion(const std::string& bookRegion);
    void buy();
};

#endif // BOOK_H



#include "Book.h"

// Constructor implementation
Book::Book(int bookId, const std::string& bookName, const std::string& bookAuthor, double bookCost) 
    : id(bookId), name(bookName), author(bookAuthor), cost(bookCost), status("available") {}

// Getters and Setters implementation...

// Methods implementation
void Book::lend() {
    if (status == "available") {
        status = "lent";
    }
}

void Book::returnBook() {
    if (status == "lent") {
        status = "available";
    }
}

void Book::lost() {
    status = "lost";
}

// EncyclopediaBook implementation
EncyclopediaBook::EncyclopediaBook(int bookId, const std::string& bookName, const std::string& bookAuthor, double bookCost, const std::string& bookType, const std::string& bookPublisher)
    : Book(bookId, bookName, bookAuthor, bookCost), type(bookType), publisher(bookPublisher) {}

std::string EncyclopediaBook::getType() const {
    return type;
}

std::string EncyclopediaBook::getPublisher() const {
    return publisher;
}

void EncyclopediaBook::setType(const std::string& bookType) {
    type = bookType;
}

void EncyclopediaBook::setPublisher(const std::string& bookPublisher) {
    publisher = bookPublisher;
}

void EncyclopediaBook::refer() {
    // Implement refer functionality here
}

// FictionBook implementation
FictionBook::FictionBook(int bookId, const std::string& bookName, const std::string& bookAuthor, double bookCost, const std::string& bookType, const std::string& bookRegion)
    : Book(bookId, bookName, bookAuthor, bookCost), type(bookType), region(bookRegion) {}

std::string FictionBook::getType() const {
    return type;
}

std::string FictionBook::getRegion() const {
    return region;
}

void FictionBook::setType(const std::string& bookType) {
    type = bookType;
}

void FictionBook::setRegion(const std::string& bookRegion) {
    region = bookRegion;
}

void FictionBook::buy() {
    // Implement buy functionality here
}



#include <iostream>
#include "Book.h"

int main() {
    // Create a book object
    Book book1(1, "The Great Gatsby", "F. Scott Fitzgerald", 10.99);

    // Print initial status
    std::cout << "Book Name: " << book1.getName() << "\nStatus: " << book1.getStatus() << std::endl;

    // Lend the book
    book1.lend();
    std::cout << "After lending, Status: " << book1.getStatus() << std::endl;

    // Return the book
    book1.returnBook();
    std::cout << "After returning, Status: " << book1.getStatus() << std::endl;

    // Mark the book as lost
    book1.lost();
    std::cout << "After being lost, Status: " << book1.getStatus() << std::endl;

    // Create an EncyclopediaBook object
    EncyclopediaBook encyclopediaBook(2, "World Atlas", "National Geographic", 29.99, "Geography", "National Geographic Society");

    // Create a FictionBook object
    FictionBook fictionBook(3, "The Da Vinci Code", "Dan Brown", 12.50, "Mystery", "American");

    return 0;
}
Leave a Comment