#C13500. Bookstore Inventory Management
Bookstore Inventory Management
Bookstore Inventory Management
You are required to implement a simple inventory management system for a bookstore. The system should support the following commands:
- ADD isbn title author quantity: Adds a new book to the inventory. If the book already exists (identified by isbn), increase its quantity by the specified amount.
- UPDATE isbn quantity: Updates the quantity of the book with the given isbn to the new value. If the book is not found, output an error message:
Book not found in inventory.
- SELL isbn quantity: Decreases the quantity of the book with the given isbn by the specified amount. If the book is not found, output
Book not found in inventory.
. If there is not enough stock, outputNot enough stock to sell.
and do not change the quantity. - CHECK: Prints the current inventory. For each book, print a line in the following format:
ISBN: {isbn}, Title: {title}, Author: {author}, Quantity: {quantity}
The commands will be given as input, one command per line. The first line contains an integer N representing the number of commands. Process the commands in the given order. The properties of the inventory are summarized by the equation below: $$\text{New Quantity} = \begin{cases} \text{Old Quantity} + \text{Added Quantity}, & \text{for ADD command (if exists)}\\[6pt] \text{New Quantity} = \text{Specified Quantity}, & \text{for UPDATE command}\\[6pt] \text{New Quantity} = \text{Old Quantity} - \text{Sold Quantity}, & \text{for SELL command (if sufficient)} \end{cases}$$
inputFormat
The first line of input is an integer N representing the number of commands. Each of the following N lines contains one command in one of the following formats:
ADD isbn title author quantity
(Note:title
andauthor
will not contain spaces; underscores represent spaces)UPDATE isbn quantity
SELL isbn quantity
CHECK
outputFormat
The output should be printed to standard output. For each CHECK
command, print the current inventory. Each book in the inventory should be printed on a separate line using the following format:
ISBN: {isbn}, Title: {title}, Author: {author}, Quantity: {quantity}
If a command (like UPDATE
or SELL
) refers to a non-existent book or if there is insufficient stock during a SELL
command, print the corresponding error message immediately:
Book not found in inventory.
Not enough stock to sell.
6
ADD 978-0132350884 Clean_Code Robert_C._Martin 10
ADD 978-0132350884 Clean_Code Robert_C._Martin 5
CHECK
UPDATE 978-0132350884 20
CHECK
SELL 978-0132350884 5
ISBN: 978-0132350884, Title: Clean_Code, Author: Robert_C._Martin, Quantity: 15
ISBN: 978-0132350884, Title: Clean_Code, Author: Robert_C._Martin, Quantity: 20
</p>