#C13804. Bookstore Inventory System
Bookstore Inventory System
Bookstore Inventory System
You are to implement a bookstore inventory system. The system supports several operations: adding books, listing all books, searching by title or author, updating inventory quantities, computing the total inventory value, and listing books with low stock. In particular, the total inventory value is calculated as (\sum_{i=1}^{n}(price_i \times quantity_i)). The commands are provided in the input via standard input (stdin), and your program should output the results to standard output (stdout). Each book entry should be output in the format: title author ISBN price quantity
(with the price formatted to two decimals), and the total inventory value should also be formatted to two decimals.
inputFormat
The input begins with an integer T -- the number of commands. The following T lines each contain a command. The available commands are:
-
ADD title author ISBN price quantity
- Add a new book with given title (string), author (string), ISBN (string), price (float) and quantity (integer).
-
LIST
- List all books in the inventory in the order they were added, one per line in the format: title author ISBN price quantity.
-
FIND_TITLE substring
- List all books whose titles contain the given substring (case-insensitive).
-
FIND_AUTHOR substring
- List all books whose authors contain the given substring (case-insensitive).
-
UPDATE ISBN quantity_change
- Update the quantity of the book with the given ISBN by adding quantity_change (an integer).
-
TOTAL
- Print the total inventory value computed as (\sum_{i=1}^{n}(price_i \times quantity_i)), formatted to two decimals.
-
LOW_STOCK [threshold]
- List all books whose quantity is less than the threshold (integer). If threshold is not provided, use the default value 5.
All outputs should be printed in the order of the commands that produce an output.
outputFormat
For commands that require output (LIST, FIND_TITLE, FIND_AUTHOR, TOTAL, LOW_STOCK), print the results exactly in the order they are executed. Each book record should be printed on its own line in the format:
title author ISBN price quantity
where price is displayed with two decimals. For the TOTAL command, output a single line with the total value (formatted to two decimals).## sample
7
ADD Title1 Author1 123 10.99 5
ADD Title2 Author2 456 15.99 3
LIST
TOTAL
FIND_TITLE Title1
UPDATE 123 5
TOTAL
Title1 Author1 123 10.99 5
Title2 Author2 456 15.99 3
102.92
Title1 Author1 123 10.99 5
157.87
</p>