Objective

In this lab you will write a program that maintains information for an online bookstore, similar to the information on Amazon. The program will allow you to add and delete books from the bookstore inventory, to search the inventory for books by name or by rat- ing, and to print out part or all of the book inventory.

The data in your book inventory will be stored in memory with the use of a linked list, with list nodes representing books in the inventory. Each node will contain members for storing a book’s name (char *) and author (char *), its rating (int) and its category (char). There are four possible categories, each of which is identified by the first character in the words (F)iction, (H)istory, (P)hilosophy and (A)rts. Your linked list must be kept in a special order, with all the fiction books first, then the history books, then the philosophy books, and finally the arts books. If there is more than one book in the same category, then the books should be kept in order of their insertion (e.g., the last history book in the inventory should be the history book most recently inserted into the list; the first art book in the inventory should be the art book that was inserted first into the list, and so on). Books with duplicate names are not allowed in the inventory. You must detect such cases, disallow them and print an error. However, you can assume that the user enters a valid author, rating, and category.

Your program should be menu driven, with the user being offered a choice of the six com- mands described below:

Insert a new book into the bookstore inventory. The program should prompt the user for a book name and author name, a rating and a category. This information should be placed in a new node that has been created using the malloc function. And then the node should be inserted at the appropriate category in the linked list that stores the inventory data. Don’t forget that the inventory must be stored in a special order, by considering the book’s category first, and then (if needed) the order of insertion. If a node with the given name is already in the inventory, an error message should be produced and the new node should not be inserted into the linked list.

Delete a book from the bookstore inventory. The program should prompt the user for the name of the book to be deleted and then delete the node containing that name from the linked list that stores the bookstore inventory. If no book with the given name is found in the inventory, an error message should be produced.

Print the bookstore inventory, following a special order. Print the name, author, rating and category of each book, with each piece of information on a separate line. A blank line should be printed between each book. The special order assumes that the fiction books appear first, then the history books, then the philosophy books, and finally the art books. If a category has more than one book, then they should be printed in order of their insertion.

Search for a book using a name. The program should print the name of the book, as well as its author, rating and category, with each piece of information on a separate line. Search results should be printed using the same ordering defined for the Print function. If no book with the provided name is found in the inventory, an error message should be produced.

Search for books in the inventory that are rated higher than or equal to a given rating. The program should print the name, author, rating and category of any book that is rated higher than or equal to an input rating, with each piece of book information on a separate line. Search results should be printed using the same ordering defined for the Print function. A blank line should be printed between each book (if more than one is found). If no book in the inventory is rated higher than or equal to the given rating, an error message should be produced.

Quit the program. When the program is given the quit command, it should delete all of the nodes in the linked list by using calls to the free function. It should then try to print the empty linked list.

Your Task

Your task is to write a complete C program that maintains a bookstore inventory. Your C program must go in a file named Lab8.c.

To assist you in the production of your program, you will be given a file that contains a skeleton of a complete program.

The skeleton program includes all of the C statements required to implement the menu driven parts of the program. It also includes a few helpful functions for reading data and printing messages. All you need to do is implement the instructions for working with the linked list that stores the bookstore inventory.

We recommend that you take the following steps:

  • Read the entire skeleton program carefully. Take note of the provided functions for reading strings, printing information about books, and for printing error messages. Using these functions will make it easier for you to satisfy the tester and marker programs.
  • Figure out how to express the required book information in a node. Add a struct definition for a linked list node to the program.
  • Add the function for inserting a node into the linked list. Your function will need to read the name, author, rating and category for the book. Test your program by trying to insert nodes into the linked list. Try to insert nodes with both new and duplicate names, and with different categories.
  • Add a function for printing the linked list. Test your program by inserting entries into the linked list and then printing them out. Are the entries in the correct order?
  • Add a function that searches the linked list for a book with the given name, and then either prints the appropriate entry, or if a book with the given name is not found, prints an error message.
  • Add a function that searches the linked list for books that are rated higher than or equal to a given rating, and then either prints the appropriate entries, or if no node with a rating higher than or equal to the provided rating is found, prints an error message.
  • Add the statements that need to be executed when the Quit command is entered. These statements should delete the linked list by using calls to the free function. To check your work, print the linked list after all of the elements have been deleted.
  • Add a function for deleting a book. It will need to search the linked list for a given name, delete the appropriate node from the linked list and then use the free func- tion to release the memory used to store the node. If the given name is not found in the bookstore inventory, print an error message.

We recommend that you test your program after attempting to complete each step. This way, if your program no longer works, you will know which statements are causing the error. Complete each step before moving on to the next one.

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.