#K92552. Store Inventory Management System
Store Inventory Management System
Store Inventory Management System
You are required to implement a store inventory management system that supports the following commands: ADD
, UPDATE
, DELETE
, and GET
. The commands are provided via standard input, and your program should output the responses to standard output.
The system maintains an inventory of items. For an ADD command, if the item already exists, its quantity is increased by the given amount; otherwise, a new item is added. The UPDATE command sets the quantity of an existing item to a new value; if the item does not exist, output Item not found
. Similarly, the DELETE command removes an item if it exists, otherwise it outputs Item not found
. The GET command prints the current inventory.
For each GET
command, print each inventory item on its own line, in the format name quantity
. If the inventory is empty, print Empty
.
You may assume that all quantities are integers. Use the dictionary (or map) data structure to simulate the inventory. In addition, note that the inventory order is the order in which items were initially added.
For example, the inventory state update after a series of commands can be formally represented as follows in LaTeX:
\[ \text{If } inventory = \{ (name_1, q_1), (name_2, q_2), \dots, (name_k, q_k) \}, \]then the output for a GET
command should be:
inputFormat
The first line contains an integer n
representing the number of commands.
Each of the next n
lines contains a command in one of the following forms:
ADD name quantity
UPDATE name quantity
DELETE name
GET
Note: quantity
is an integer, and name
is a string with no spaces.
outputFormat
For each command, output as follows:
- GET: Print each inventory item on a separate line in the format
name quantity
. If the inventory is empty, outputEmpty
. - UPDATE and DELETE: If the specified item does not exist, output
Item not found
immediately. - ADD: No output is expected.
All output should be printed to standard output.
## sample4
ADD Apples 10
GET
DELETE Bananas
GET
Apples 10
Item not found
Apples 10
</p>