CSCI-20 Assignment #3 Binary search trees. (160 points) ... Write a BinaryTree class and a client program to manage...

advertisement
CSCI-20 Assignment #3 Binary search trees. (160 points) Due 4/5/16
Write a BinaryTree class and a client program to manage the class. You will also need to adapt
your linked list class for this project. Your program will implement a tree of library books and a
list of people, each of which may have books checked out of the library.
The tree holds books, each of which has a title (a string), author (a string), ID# (an integer), and a
pointer to a person (if checked out, NULL if not checked out). People have a name (a string), a
set of books checked out (a tree of books), and a telephone number (a string). For simplicity,
people have only one name, e.g., "John", not "John Black".
Books checked out by the person will be copied (not removed) from the library's tree and added
to the customer's tree. The library tree's original book entry will then have its customer pointer
set to point to the person who checked it out. The customer pointer in the checked-out tree will
be unused. To check in the book, find the person, find the book in the person's tree, if there find
the book in the library's tree and NULL the person pointer, and then remove the book from the
person's tree.
The program will process the following set of commands, with data shown in parenthesis, and
tab-separated fields:
A (title) (author) (id)
Add the book to the library tree
B (customer name) (phone #)
Add the customer to the list of customers
C (id) (customer name)
Check out the book the customer, unless already checked out, not there, or no such
customer
D (id)
Remove the book from the library, unless checked out or not there
I (id) (customer name)
Check in the customer's book, unless not checked out or no such customer
O
Print all the books in the library that are checked out and by whom in-order
N
Print all the books in the library that are not checked out in in-order
P
Print the list of customers and all the books they have checked out in in-order
Q
Print all the books in the library in in-order, marking checked-out books with *
R
Print all the books in the library in pre-order, marking checked-out books with *
S
Print all the books in the library in post-order, marking checked-out books with *
Z
Stop processing and close files, etc.
Read the lines of text from a file and write output to a file directly within your program. Take
the file names off of the command line using argc and argv. The input is a series of text lines:
the first letter on the line is a command and the rest of the line is the data needed to execute the
command in tab-separated fields. Output will be an audit of the command lines read by the
program, as well as any output requested by the command, or needed to show that the command
is executed correctly. Stop processing when you reach the 'Z' line in the input file. If the fine
does not have a 'Q' command last before the 'Z', then treat end-of-file as a final 'Q' command.
When you print the book tree for commands 'Q', 'R' and 'S', print the book title, author and ID
number, and put the '*' after the ID number on the line.
I have a test data set for you to test with. Test with at least one other set, with at least 25 books
and 10 customers, checking out and back in all the books at least twice each (and at least one
book out and in to each customer).
Download