#C179. Library Management System

    ID: 45033 Type: Default 1000ms 256MiB

Library Management System

Library Management System

You are to implement a simple library management system. The system supports operations to add books, search for books by a specific attribute, check out a book, return a book, and list all books currently in the library. The system should use the following commands:

  • ADD: Add a book or update the number of copies if the book (identified by its ISBN) already exists. The format is: ADD title;author;pub_year;isbn;copies where fields are separated by semicolons.
  • SEARCH: Search for books by an attribute. The command format is: SEARCH attribute value. The attribute can be one of title, author, pub_year, or isbn. The search should be case-insensitive for title and author, and a substring match for these two fields. If no matching books are found, print "No results found".
  • CHECKOUT: Check out a book (i.e. reduce the number of available copies by one) using its ISBN. Command format: CHECKOUT isbn. If the checkout is successful (i.e. at least one copy is available), print "True"; otherwise print "False".
  • RETURN: Return a book (i.e. increment the number of available copies by one) using its ISBN. Command format: RETURN isbn. Print "True" if the return is successful (i.e. the book exists in the library), otherwise print "False".
  • LIST: List all books in the library. For each book, print a line in the following format:
    Title: \(title\), Author: \(author\), Year: \(pub_year\), ISBN: \(isbn\), Copies Available: \(copies\).
    If there are no books in the library, print "No books in library".
  • EXIT: Terminate the command input.

The details for each book should be formatted as follows:

$$\text{Title: } title, \text{ Author: } author, \text{ Year: } pub\_year, \text{ ISBN: } isbn, \text{ Copies Available: } copies$$

inputFormat

The input will be read from standard input. The first line contains an integer (N) representing the total number of commands. Each of the following (N) lines contains one command as described above. The commands are processed in order. The command "EXIT" signifies the end of input and does not produce output.

outputFormat

For commands that require output (SEARCH, CHECKOUT, RETURN, and LIST), print the results to standard output. For the SEARCH and LIST commands, output one book per line using the specified format. If no books match the SEARCH criteria, output "No results found". If the library is empty for the LIST command, output "No books in library".## sample

6
ADD Python 101;Mike Driscoll;2020;12345;3
ADD Learn C++;Bjarne Stroustrup;1998;67890;1
LIST
SEARCH title Python
EXIT
Title: Python 101, Author: Mike Driscoll, Year: 2020, ISBN: 12345, Copies Available: 3

Title: Learn C++, Author: Bjarne Stroustrup, Year: 1998, ISBN: 67890, Copies Available: 1 Title: Python 101, Author: Mike Driscoll, Year: 2020, ISBN: 12345, Copies Available: 3

</p>