#C13584. Inventory Management System
Inventory Management System
Inventory Management System
You are required to implement an interactive inventory management system for a small store. The system supports adding items, updating their quantities, removing items, displaying the current inventory, and computing the total value of all items.
The commands you need to implement (each provided on a separate line) are as follows:
- add <name> <quantity> <price>: Add an item with the given name, quantity (an integer), and price (a floating point number). If the item already exists, output the error message:
Item 'name' already exists in the inventory.
- update <name> <quantity>: Update the quantity of an existing item. If the item does not exist, output:
Item 'name' does not exist in the inventory.
- remove <name>: Remove an item from the inventory. If the item does not exist, output:
Item 'name' does not exist in the inventory.
- display: Print all items in the inventory. For each item, print a line in the format:
name: Quantity: quantity, Price: price
. - total: Compute and print the total value of the inventory in the format:
Total Value: computed_value
. The total value is computed as \(\sum (quantity \times price)\).
The program must read from standard input (stdin) and write all outputs to standard output (stdout). Handle error cases as specified and continue processing subsequent commands.
inputFormat
The first line of input contains an integer \(N\) representing the number of commands. The next \(N\) lines each contain one command. Commands are one of the following:
add <name> <quantity> <price>
update <name> <quantity>
remove <name>
display
total
Note that quantity
is an integer and price
is a float.
outputFormat
For each command that produces output, print the result on a new line. The display
command prints one line per item in the inventory in the order they were added, in the format:
name: Quantity: quantity, Price: price
The total
command prints a single line in the format:
Total Value: computed_value
For error cases, print the corresponding error message.
## sample7
add Apple 50 0.5
add Banana 100 0.2
add Orange 75 0.3
update Apple 60
remove Banana
display
total
Apple: Quantity: 60, Price: 0.5
Orange: Quantity: 75, Price: 0.3
Total Value: 52.5
</p>