#C4030. Library Book Management System
Library Book Management System
Library Book Management System
You are required to implement a simple library management system. The system should support the following commands:
- ADD <BookID> <Title> <Author> <Genre>: Adds a new book with the given BookID, Title, Author, and Genre. Note that each field is a single word (underscores may be used in place of spaces).
- LIST BY AUTHOR: Lists all the books sorted in ascending order by the author's name. If two books have the same author, their relative order should remain as in the input.
- LIST BY GENRE <Genre>: Lists all the books with the given genre, sorted in ascending order by the author's name.
- EXIT: Terminates the command input.
Input Format: The input consists of multiple lines, each representing a command. The input is terminated by the "EXIT" command. Commands will be given exactly as described above.
Output Format: For each list command the system should output the requested list of books. Each book is printed on a separate line in the following format:
BookID Title Author Genre
If there is no output (for example, when only ADD commands are executed followed by EXIT), then nothing should be printed.
Note: Sorting by author means lexicographical order based on the author's name. For books with equal authors, preserve the order of insertion.
inputFormat
The input is a sequence of commands, each provided on a separate line from standard input. The commands can be one of the following:
ADD <BookID> <Title> <Author> <Genre>
LIST BY AUTHOR
LIST BY GENRE <Genre>
EXIT
The input terminates with the EXIT
command.
outputFormat
For each LIST
command, the output should be printed to standard output. Each book matching the command should be output on its own line in the format:
BookID Title Author Genre
If a command does not require output (like ADD
or EXIT
), then nothing should be printed.
ADD 1 The_Hobbit J.R.R._Tolkien Fantasy
ADD 2 1984 George_Orwell Dystopian
ADD 3 Brave_New_World Aldous_Huxley Dystopian
ADD 4 The_Lord_of_the_Rings J.R.R._Tolkien Fantasy
LIST BY AUTHOR
EXIT
3 Brave_New_World Aldous_Huxley Dystopian
2 1984 George_Orwell Dystopian
1 The_Hobbit J.R.R._Tolkien Fantasy
4 The_Lord_of_the_Rings J.R.R._Tolkien Fantasy
</p>