Untitled
unknown
plain_text
2 years ago
1.7 kB
9
Indexable
#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;
}
bool checkAvailability(int requested_copies) {
return requested_copies <= stock_position;
}
double calculateTotalCost(int requested_copies) {
return price * requested_copies;
}
};
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;
getline(cin, title);
cout << "Enter the author of the book: ";
string author;
getline(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;
}
Editor is loading...