#C9438. Inventory Management System
Inventory Management System
Inventory Management System
This problem involves managing a simple inventory system. You need to implement operations to add, update, delete, check stock, and display inventory items. Each product is identified by a unique product ID.
Operations are defined as follows:
- ADD: Add a new product or update an existing product using the command format:
ADD product_id name quantity price
. - UPDATE_QUANTITY: Update the quantity of a product:
UPDATE_QUANTITY product_id quantity
. - UPDATE_PRICE: Update the price of a product:
UPDATE_PRICE product_id price
. - DELETE: Remove a product from the inventory:
DELETE product_id
. - CHECK_STOCK: Check the stock quantity of a product:
CHECK_STOCK product_id
. If the product does not exist, outputNone
. - DISPLAY: Display all products in ascending order by product ID. Each product is printed in the format:
product_id name quantity price
.
You can view the inventory mathematically as follows:
$$\text{Inventory}(pid)=\{\text{name},\,\text{quantity},\,\text{price}\}$$
inputFormat
The first line contains an integer n representing the number of commands. Each of the following n lines contains a command in one of the following formats:
ADD product_id name quantity price
UPDATE_QUANTITY product_id quantity
UPDATE_PRICE product_id price
DELETE product_id
CHECK_STOCK product_id
DISPLAY
outputFormat
For each CHECK_STOCK
and DISPLAY
command, output the result on a new line. For CHECK_STOCK
, output the quantity if the product exists, or None
if it does not. For DISPLAY
, output each product's details on a new line in the format: product_id name quantity price
.
6
ADD 101 Apple 50 30
CHECK_STOCK 101
DISPLAY
UPDATE_QUANTITY 101 60
UPDATE_PRICE 101 35
DISPLAY
50
101 Apple 50 30
101 Apple 60 35
</p>