Untitled
unknown
plain_text
a year ago
1.7 kB
3
Indexable
Never
#include <iostream> #include <string> using namespace std; class Book { private: string author; string title; double price; string publisher; int stock_position; public: Book(string a, string t, double p, string pub, int stock) : author(a), title(t), price(p), publisher(pub), stock_position(stock) {} void displayDetails() { cout << "Title: " << title << "\nAuthor: " << author << "\nPrice: $" << price << "\nPublisher: " << publisher << "\nStock Position: " << stock_position << endl; } book checkAvailability(int requested_copies) { return requested_copies <= stock_position; } double calculateTotalCost(int requested_copies) { return price * requested_copies; } }; book :: getdata(x,y) int main() { Book book1("J.K. Rowling", "Harry Potter and the Sorcerer's Stone", 12.99, "Scholastic", 10); cout << "Enter the title of the book: "; string title; getdata(cin, title); cout << "Enter the author of the book: "; string author; getdata(cin, author); if (title == book1.getTitle() && author == book1.getAuthor()) { cout << "Enter the number of copies required: "; int requested_copies; cin >> requested_copies; if (book1.checkAvailability(requested_copies)) { double total_cost = book1.calculateTotalCost(requested_copies); cout << "Total cost for " << requested_copies << " copies: $" << total_cost << endl; } else { cout << "Required copies not in stock." << endl; } } else { cout << "Book not found." << endl; } return 0; }