#C11237. Library Inventory Management System
Library Inventory Management System
Library Inventory Management System
You are required to implement a simple library inventory management system. The system will allow adding new books, removing existing books, and searching for books by their unique identifier, title, or author.
When a book is added using the ADD command, if the book already exists (i.e. the same unique id is provided), update its title and author. The REMOVE command will remove the book with the provided id if it exists.
The search commands are as follows:
- SEARCH_ID: If found, output the book details as id title author; otherwise output Book not found.
- SEARCH_TITLE and SEARCH_AUTHOR: Output all matching book entries in the format id title author (one per line) sorted in increasing order of id. If no matching books are found, output No books found.
All input should be read from standard input and all output should be written to standard output.
The following operations are supported:
- ADD
- REMOVE
- SEARCH_ID
- SEARCH_TITLE
- SEARCH_AUTHOR
The input format is described below.
Note: When outputting multiple lines as a result of a search, use a newline character (\n) to separate each book record.
For any mathematical notation, use \( \LaTeX \) format. (There are no formulas in this problem though.)
inputFormat
The first line of input contains an integer Q indicating the number of operations.
Each operation is provided as follows:
- If the operation is ADD, the next three lines are:
- An integer representing the book_id
- A string for the title
- A string for the author
- If the operation is REMOVE, the next line contains the book_id (integer).
- If the operation is SEARCH_ID, the next line contains the book_id (integer).
- If the operation is SEARCH_TITLE, the next line contains the title (string).
- If the operation is SEARCH_AUTHOR, the next line contains the author (string).
For each search operation, the system should output the result to standard output immediately.
outputFormat
For SEARCH_ID: If the book is found, output in the format: id title author. Otherwise, output Book not found.
For SEARCH_TITLE and SEARCH_AUTHOR: Output all matching books (if any) in the format id title author with each record on a new line, sorted in increasing order by id. If no matching book is found, output No books found.
No output is required for ADD or REMOVE operations.
## sample6
ADD
1
The Great Gatsby
F. Scott Fitzgerald
SEARCH_ID
1
REMOVE
1
SEARCH_ID
1
ADD
2
The Great Gatsby
F. Scott Fitzgerald
SEARCH_TITLE
The Great Gatsby
1 The Great Gatsby F. Scott Fitzgerald
Book not found
2 The Great Gatsby F. Scott Fitzgerald
</p>