#C12908. Bookstore Inventory and Sales Simulation
Bookstore Inventory and Sales Simulation
Bookstore Inventory and Sales Simulation
This problem simulates a bookstore inventory system. You will use two classes: Book
and Sale
. A Book
is defined by its title, author, ISBN, price, and current stock. A Sale
represents the sale of a given quantity of that book. A sale is successful if the Book
has enough stock; if so, the sale will update the stock and compute the total sale price using the formula: $$total\_price = price \times quantity$$. Otherwise, the sale is rejected.
Your task is to simulate a series of sales operations on a single book. For each sale operation, if the sale is recorded, print the total price (formatted to one decimal place); if not, print 0.
inputFormat
The input is given from stdin and consists of several lines:
- The first line contains the title of the book (a string).
- The second line contains the author (a string).
- The third line contains the ISBN (a string).
- The fourth line contains the price (a floating point number).
- The fifth line contains the initial stock (an integer).
- The sixth line contains an integer Q, the number of sale transactions.
- Each of the next Q lines contains an integer representing the sale quantity for that transaction.
outputFormat
For each sale transaction, output a line:
- If the sale is successful (i.e. there is sufficient stock), output the total sale price computed as
price * quantity
formatted to one decimal place. - If the sale cannot be completed due to insufficient stock, output
0
.
The output should be printed to stdout.
## sampleThe Great Gatsby
F. Scott Fitzgerald
978-0743273565
15.5
20
3
5
10
8
77.5
155.0
0
</p>