#C13125. Author and Book Management

    ID: 42629 Type: Default 1000ms 256MiB

Author and Book Management

Author and Book Management

In this problem, you are required to implement two classes: Author and Book. The Author class stores information about an author including their name, year of birth, and a list of written books, while the Book class stores the title, publication year, and the associated Author object. Your task is to process commands from the standard input to create an author and add books to the author. You will then output the details of the author and specific books as requested.

The methods to implement are as follows:

  1. (\textbf{Author(name, year_of_birth)}): Initializes the author with the given name and year of birth. Initially, the list of written books is empty.

  2. (\textbf{add_book(book)}): Adds a book to the list of books written by the author.

  3. (\textbf{list_books()}): Returns the list of book titles written by the author.

  4. (\textbf{details()}): Returns a string containing the author details in the format: (\texttt{Author: }) (\texttt{Year of Birth: <year_of_birth>}) (\texttt{Books Written: , , ... })

  5. (\textbf{Book(title, author, year_of_publication)}): Initializes the book with its title, associated author, and publication year.

  6. (\textbf{details()}): Returns a string with the book details in the format: (\texttt{Book Title: }) (\texttt{Publication Year: <year_of_publication>}) (\texttt{Author: <author's name>})

The commands that your program must support are:

  • AUTHOR name year
  • BOOK title year
  • AUTHOR_DETAILS
  • BOOK_DETAILS index

Input is read from standard input and output should be printed to standard output. Note that the AUTHOR command is guaranteed to appear before any BOOK commands, and the index provided in BOOK_DETAILS is valid.

inputFormat

The first line contains an integer T, representing the number of commands. Each of the next T lines contains one command in one of the following forms:

  1. AUTHOR name year
  2. BOOK title year
  3. AUTHOR_DETAILS
  4. BOOK_DETAILS index

The name and title will be single-word strings, and year and index are integers.

outputFormat

For each command that requires an output, print the corresponding details:

  • For AUTHOR_DETAILS, print three lines:

    1. Author:
    2. Year of Birth:
    3. Books Written: , , ... (if no books, print an empty string after the colon)
  • For BOOK_DETAILS, print three lines:

    1. Book Title:
    2. Publication Year:
    3. Author: <author's name>## sample
4
AUTHOR John 1970
BOOK SampleBook 2020
AUTHOR_DETAILS
BOOK_DETAILS 0
Author: John

Year of Birth: 1970 Books Written: SampleBook Book Title: SampleBook Publication Year: 2020 Author: John

</p>