#C9418. Bookstore Management System

    ID: 53509 Type: Default 1000ms 256MiB

Bookstore Management System

Bookstore Management System

You are required to implement a bookstore management system. The system should support operations to add books, view the inventory, search for a book by title, and purchase a book.

Operations:

  • ADD <Title> <Author> <Price> <Stock>: Adds a new book or updates an existing one. If the book exists, update its price and increase its stock. Note that the updated stock is given by the formula: \(S_{new}=S_{old}+S_{add}\).
  • VIEW: Displays all books in the inventory. Each book is shown in the format: Title Author Price Stock with the price printed with 2 decimal places.
  • SEARCH <Title>: Searches and displays details of the book with the given title. If not found, output Book not found.
  • PURCHASE <Title>: Reduces the stock of the specified book by one if available, and outputs Purchased <Title>. If the book is not available for purchase (i.e. not in inventory or stock is 0), output Book not available.

The input will be given from standard input (stdin) and the output should be printed to standard output (stdout). Ensure that you process the input commands correctly and produce the expected line-by-line output.

inputFormat

The first line of input contains an integer n representing the number of operations. The next n lines each contain a command in one of the following formats:

  • ADD Title Author Price Stock
  • VIEW
  • SEARCH Title
  • PURCHASE Title

Note: All tokens are separated by spaces. The Price is a floating point number and Stock is an integer. Titles and authors will not contain spaces.

outputFormat

For each operation that produces output (VIEW, SEARCH, and PURCHASE), print the result on a new line. For the VIEW command, print one line per book in the current inventory.

## sample
7
ADD TheHobbit Tolkien 15.99 5
ADD HarryPotter Rowling 12.50 8
VIEW
SEARCH TheHobbit
PURCHASE TheHobbit
PURCHASE Dune
VIEW
TheHobbit Tolkien 15.99 5

HarryPotter Rowling 12.50 8 TheHobbit Tolkien 15.99 5 Purchased TheHobbit Book not available TheHobbit Tolkien 15.99 4 HarryPotter Rowling 12.50 8

</p>