#C6577. Library Management System
Library Management System
Library Management System
You are required to implement a library management system that supports various operations including adding users, adding books, borrowing books, returning books, and checking the status of a book. The operations will be provided via standard input with the following commands:
- ADD_USER user_id name: Add a new user.
- ADD_BOOK isbn title: Add a new book.
- BORROW_BOOK user_id isbn: Allow a user to borrow a book if it is available.
- RETURN_BOOK user_id isbn: Allow a user to return a book they have borrowed.
- BOOK_STATUS isbn: Check whether a book is available or borrowed. If borrowed, display the borrowing user's ID.
Note: The total number of commands is given by $Q$. Every operation that is expected to have an output (i.e. BORROW_BOOK, RETURN_BOOK, BOOK_STATUS) must print a message to standard output. The expected messages are:
- Book borrowed successfully
- Cannot borrow book
- Book returned successfully
- Cannot return book
- Book is available
- Book is borrowed by user user_id
inputFormat
Input is given via standard input. The first line contains an integer (the number of operations). Each of the following lines contains a command in one of the following formats:
• ADD_USER user_id name • ADD_BOOK isbn title • BORROW_BOOK user_id isbn • RETURN_BOOK user_id isbn • BOOK_STATUS isbn
Note: All tokens are separated by spaces. The commands ADD_USER and ADD_BOOK do not produce any output.
outputFormat
For every command that produces output (i.e. BORROW_BOOK, RETURN_BOOK, BOOK_STATUS), print the corresponding message on a new line. The messages should exactly match one of the following:
• Book borrowed successfully • Cannot borrow book • Book returned successfully • Cannot return book • Book is available • Book is borrowed by user <user_id>## sample
6
ADD_USER 1 Alice
ADD_BOOK 123456 The_Great_Gatsby
BORROW_BOOK 1 123456
BOOK_STATUS 123456
RETURN_BOOK 1 123456
BOOK_STATUS 123456
Book borrowed successfully
Book is borrowed by user 1
Book returned successfully
Book is available
</p>