Write a program that maintains a list of books for a library. The program must accept commands to make insertions and deletions in this list, while simultaneously maintaining the list in alphabetical order for three StrType keys: Subject, Author, and Title.

Input

1. The book information created in previous executions of this program, if any, is stored in text file "books.txt". Each book's information is on three consecutive lines. The format of each line is described in the table below:

Line Information
1 Book Title
2 Author (last name, first name)
3 Subject

2. The program inputs commands from the user (keyboard) to insert, delete, list by key, and quit. You are free to implement the "user interface" part of the program as you wish, as long as it is easy to use.

Output

1. The results of each operation should be written to the screen. In addition, transaction information describing the processing of each command should be written to an output file. (For instance, for an Insert command, the output file should contain the title, author, and subject information, as well as the location where the record was inserted and the location of its entry in each ordering array.) The information in the output file should be neatly formatted and clearly labeled.

2. The "books.txt" text file should be rewritten to contain the updated book information.

Data Structures

The records containing information about each book (subject, author, and title strings) must be stored in an array. These records may be stored in consecutive array slots in the order in which they are inserted. For example, if the book information is stored in an array called bookData, bookData[0] contains information about the first book inserted, bookData[1] contains information about the second book inserted and so on.

The list must be maintained in order by title, in order by author, and in order by subject by using arrays of pointers (indexes), one for each key. For instance, suppose the key order information is stored in arrays of KeyOrderType, as described below:

typddef int[MAX_BOOKS] KeyOrderType;
titleOrder : KeyOrderType;
authorOrder : KeyOrderType;
subjectOrder : KeyOrderType;

The zero'th array slot contains the index of the first book record with the appropriate key. For example, titleOrder[0] indicates the index of the book that comes first alphabetically by title. If titleOrder[0] = 5, then bookData[5] contains the first alphabetical title. The next book, in alphabetical order by title, would be found in the bookData array at the index indicated by titleOrder[1]. For index >= 0, titleOrder[index]contains the index in bookData of the next title in the alphabetic ordering. The authorOrder and subjectOrder arrays work similarly. (The arrays may be bound together in a struct, if you wish. They are described here as separate entities only for clarity.)

Commands

The program must be able to process the following commands:

Command Processing
INSERT Prompt the user for the author, title, and subject. Add entry for this book in the next available location in the bookData array, then update the titleOrder, authorOrder, and subjectOrder arrays. Print a message to the screen and write transaction information to the output file. If the bookData array is full, print an error message and abort the insertion, leaving all of the arrays unchanged.
DELETE Prompt the user for the name of the book to delete. (You can assume that this is a unique key.) Search for the title to be deleted. If it is found, all the ordering arrays must be updated. Print a message to the screen and write transaction information to the output file. If the book is not found, leave the list and ordering arrays unchanged, and print an error message.
LIST Prompt the user to specify which key to use for ordering the output. Print out the information about each book, in the indicated order, to the screen and to the transaction file. Format this information clearly. If the list is empty, print an appropriate message.
QUIT Prompt the user to verify that he or she wants to quit; if so, save the book information to file books.txt" and terminate the program.

Deliverables

  • Your design with CRC cards for each class
  • Your listing of source program and books.txt file
  • A listing of your test plan as input to the program
  • A listing of the output from your test run
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.