CS 222-01-14W: Data Structures Program 5 Advanced Print Queue


Category: You will Instantly receive a download link for .zip solution file upon Payment


5/5 - (5 votes)

Make a directory called “PG5” in the root of your CS222-01-14W folder. Place all the source
code and include files in this directory. Place a (possibly empty) file called “DONE” into this
folder when you are ready for your program to be graded.
You are to write software to store library books in a red-black tree. The binary tree should keep
track of each book title and how many copies of each book are on hand. The librarian will
process books with the following commands:
is the name of the book you wish to add. is allowed to contain spaces and
punctuation. If the book does not already exist, it is to be added to the tree with one copy
recorded as being on hand. If the book is already there, then one should be added to the number
of copies on hand.
This should print out a list of all the books in the library in alphabetical order, along with the
copies on hand of each book. The output should be legible, though it doesn’t have to be lined up
perfectly in columns. If the library is empty, a message should be printed stating this fact.
This removes a book from the library. If there is more than one copy present in the library, this
will shrink the number of copies by one. If there is only one copy, the record should be
expunged from the database. If an attempt is made to delete a book that is not in the library, an
error message should be printed.
This should print the total number of books in the library.
Your program should end when the end-of-file is reached. When it ends, it should thank the user
for using the program. Aside from the specific cases mentioned above, you can assume the input
is formatted correctly. There won’t be “extra” commands. There won’t be lines of complete
gibberish. When the command is “ADD” or “DELETE”, there will be exactly one space
between the command and the book title. There will be no extraneous spaces or tabs or anything
floating about.
If a command doesn’t result in an error, you should print something to indicate that the command
completed successfully. With PRINT and COUNT, an output is obvious, but you should print an
acknowledgement of some kind even if there is no obvious answer to your request.
Here is an example.
ADD Harry Potter and the Philosopher’s Stone
ADD Harry Potter and the Philosopher’s Stone
DELETE Harry Potter and the Chamber of Secrets
The output for this example, should resemble:
One copy of Harry Potter and the Philosopher’s Stone has been
added to the library.
One copy of Harry Potter and the Philosopher’s Stone has been
added to the library.
Harry Potter and the Chamber of Secrets is not in the library
and cannot be deleted.
The library contains the following books:
Harry Potter and the Philosopher’s Stone: 2 copies.
There are 2 books in the library at this time.
Thank you for using this program!
Your output doesn’t have to look exactly like this, but notice how user-friendly it is: you can tell
from the answer what the question was. Your output should be the same way.