Untitled
unknown
plain_text
2 years ago
1.2 kB
10
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) {
title = title;
author = author;
price = price;
publisher = publisher;
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()
{
Book book1("The Great Gatsby", "F. Scott Fitzgerald", 100, "Penguin", 10);
book1.display();
int copiesRequired;
cout << "How many copies do you need? ";
cin >> copiesRequired;
if (book1.stock >= copiesRequired)
{
int totalCost = book1.price * copiesRequired;
cout << "The total cost is " << totalCost << endl;
}
else
{
cout << "The book is not in stock." << endl;
}
return 0;
}Editor is loading...