#C14742. Library Management System Simulation

    ID: 44425 Type: Default 1000ms 256MiB

Library Management System Simulation

Library Management System Simulation

You are required to implement a simple library management system. The system consists of three main classes:

  • Book: Represents a book with attributes title, author, and isbn.
  • Member: Represents a library member with attributes name and member_id.
  • Library: Manages collections of books and members and handles the operations of lending and returning books. It supports the following operations:
    • ADD_BOOK <title> <author> <isbn>: Adds a book to the library. If a book with the given ISBN already exists, an error should be reported.
    • REGISTER_MEMBER <name> <member_id>: Registers a new member to the library. Duplicate IDs should trigger an error.
    • LEND_BOOK <isbn> <member_id>: Lends a book to a member. Errors must be reported if the book does not exist, if the member does not exist, or if the book is already borrowed.
    • RETURN_BOOK <isbn>: Returns a borrowed book. If the book is not currently borrowed, an error is reported.
    • STATUS: Prints the list of currently borrowed books. Each borrowed book is printed on a new line in the format <isbn> <member_id>. If no books are borrowed, print No borrowed books.

All error messages must be printed in the format:

$$ \texttt{Error: } $$

The program should process a series of commands read from the standard input and print outputs to the standard output.

inputFormat

The first line of input contains an integer N representing the number of commands. Each of the following N lines contains a command. The commands are formatted as follows (arguments are separated by a single space):

  • ADD_BOOK <title> <author> <isbn>
  • REGISTER_MEMBER <name> <member_id>
  • LEND_BOOK <isbn> <member_id>
  • RETURN_BOOK <isbn>
  • STATUS

Note: It is guaranteed that none of the fields (title, author, isbn, etc.) contain spaces.

outputFormat

The output is generated only by the commands that produce output:

  • If an operation fails (e.g. trying to add an existing book, lending a nonexistent book, etc.), print the error message in the format Error: <error_message>.
  • The STATUS command prints all currently borrowed books, one per line in the format <isbn> <member_id>. If there are no borrowed books at the time of the STATUS command, print No borrowed books.
## sample
6
ADD_BOOK Title1 Author1 ISBN001
REGISTER_MEMBER Member1 ID001
LEND_BOOK ISBN001 ID001
STATUS
RETURN_BOOK ISBN001
STATUS
ISBN001 ID001

No borrowed books

</p>