#C14133. Library Management System

    ID: 43749 Type: Default 1000ms 256MiB

Library Management System

Library Management System

Design and implement a Library Management System using Object-Oriented Programming. The system maintains a collection of books, where each book has a name, an author, and a genre. The system supports the following operations:

  • Add Book: Add a new book to the library.
  • Remove Book: Remove a book by its name. If the book does not exist, output an appropriate message.
  • Search by Author: Return a list of all books written by a specified author.
  • Count by Genre: Return a dictionary mapping each genre to the number of books in that genre.
  • List All Books: List all books in the library.

This problem requires you to design a class Library that implements these functionalities. In your solution, the Library class should have the following methods:

  • \( add\_book(book\_name, author, genre) \)
  • \( remove\_book(book\_name) \)
  • \( search\_books\_by\_author(author) \)
  • \( count\_books\_by\_genre() \)
  • \( list\_all\_books() \)

You will implement a program that reads commands from the standard input and writes the appropriate output to the standard output.

inputFormat

The first line contains an integer \( n \) representing the number of commands. Each of the next \( n \) lines contains a command in one of the following formats, with fields separated by semicolons (;):

  • add;book_name;author;genre
  • remove;book_name
  • search;author
  • count
  • list

For example: add;Book One;Author A;Fiction

outputFormat

For each command except for the add command, output the result on a new line:

  • For remove: output the removal result message.
  • For search: output a list of books (in a Python-like list of dictionaries format) by the specified author.
  • For count: output a dictionary (Python-like format) mapping genres to their respective counts.
  • For list: output the list of all books currently in the library (Python-like list of dictionaries).
## sample
5
add;Book One;Author A;Fiction
add;Book Two;Author B;Non-Fiction
list
remove;Book One
list
[{'book_name': 'Book One', 'author': 'Author A', 'genre': 'Fiction'}, {'book_name': 'Book Two', 'author': 'Author B', 'genre': 'Non-Fiction'}]

Book 'Book One' removed from the library. [{'book_name': 'Book Two', 'author': 'Author B', 'genre': 'Non-Fiction'}]

</p>