#K61632. Library Management System
Library Management System
Library Management System
You are required to implement a simple library management system. In this system, you can add books, issue books, return books, and check the inventory of a book. The operations will be provided as commands to your program. You should maintain the inventory of books, where each book is identified by an integer book_id and a string book_name. When processing commands:
- ADD: Add a book to the system. If a book with the given book_id already exists, increase its quantity by 1.
- ISSUE: Issue a book if available. This decrements the quantity if the available quantity is more than zero.
- RETURN: Return a book. This increments the quantity if the book exists in the system.
- INVENTORY: Check the current status of a book. The output should be the book_id, book_name (or None if the book is not found), and its quantity.
Internally, you may consider that the operations follow the following formulas:
\(quantity = initial\_quantity + \text{number of ADD operations} - \text{number of ISSUE operations} + \text{number of RETURN operations}\)
Implement your solution to read from standard input and write the results of every INVENTORY query to standard output.
inputFormat
The first line of input contains an integer n which denotes the number of operations. The next n lines each contain one operation in one of the following formats:
ADD <book_id> <book_name>
ISSUE <book_id>
RETURN <book_id>
INVENTORY <book_id>
All book_id values are integers, and book_name is a single-word string without spaces.
outputFormat
For each INVENTORY
command encountered in the input (in the order they appear), output a single line with three values separated by a space:
book_id book_name quantity
If the book is not present in inventory, output None
as the book_name and 0
as the quantity.
10
ADD 1 HarryPotter
ADD 2 LordOfTheRings
ISSUE 1
ISSUE 1
RETURN 1
INVENTORY 1
INVENTORY 2
ADD 2 LordOfTheRings
INVENTORY 2
INVENTORY 3
1 HarryPotter 1
2 LordOfTheRings 1
2 LordOfTheRings 2
3 None 0
</p>