Untitled
unknown
plain_text
2 years ago
1.4 kB
11
Indexable
#include <iostream>
#include <string>
using namespace std;
class Book {
public:
string title;
string author;
int price;
string publisher;
int stock;
Book() {
title = "";
author = "";
price = 0;
publisher = "";
stock = 0;
}
Book(string title, string author, int price, string publisher, int stock) {
this->title = title;
this->author = author;
this->price = price;
this->publisher = publisher;
this->stock = stock;
}
void display() {
cout << "Title: " << title << endl;
cout << "Author: " << author << endl;
cout << "Price: " << price << endl;
cout << "Publisher: " << publisher << endl;
cout << "Stock: " << stock << endl;
}
};
int main() {
// Create a book object.
Book book1("The Great Gatsby", "F. Scott Fitzgerald", 100, "Penguin", 10);
// Display the book details.
book1.display();
// Get the number of copies required.
int copiesRequired;
cout << "How many copies do you need? ";
cin >> copiesRequired;
// Check if the book is available.
if (book1.stock >= copiesRequired) {
// The book is available. Display the total cost.
int totalCost = book1.price * copiesRequired;
cout << "The total cost is " << totalCost << endl;
} else {
// The book is not available. Display an appropriate message.
cout << "The book is not in stock." << endl;
}Editor is loading...