Project 3 - A Bookstore

Due - Monday, December 20, 2004

For this project, you will build on your Lab 8. This program will call upon the functions you wrote for Lab 8 to open a file and build an array of structures which store information about an inventory of books at a bookstore. This program should the call a function that will show the user a menu and ask the user which operation she would like to perform. The operations you should implement are the following:
  1. Add a New Book: If the user chooses to add a new book to the inventory, you should ask her for the name of the book, the name of the book's author, the ISBN number of the book, the price of the book, and the number of that particular book that are in the inventory. Store this information in the appropriate position in the array and perform any other necessary updates.
  2. Delete a Book: If the user chooses to delete a book from the inventory, you should ask her which book she would like to delete. The user should enter a number corresponding to the selected book and your program should delete that entry from the array.
  3. Purchase a Book: If the user chooses to purchase a book, you should ask her which book she would like to purchase. The user should enter a number corresponding to the selected book and your program should subtract 1 from the number in the inventory for that particular book.
  4. Search: If the user chooses to search for a particular book, your program should ask the user for the author of the book she would like to search for. Then, perform a linear search of the array and print out any books by that author.
  5. Quit: If the user chooses to quit, you should ask the user for the name of the file where she would like to save the updated inventory. Then, save all of the information stored in the array into a file with that name. Make sure you also store the number of books in the inventory as the first character(s) of the file.
An example run of your program might look as follows:

Inventory:
(1 of 3)
Title: The Poisonwood Bible
Author: Kingsolver, Barbara
ISBN: 0060930535
Price: 10.50
Number Remaining: 4
(2 of 3)
Title: She's Come Undone
Author: Lamb, Wally
ISBN: 0671021001
Price: 7.99
Number Remaining: 12
(3 of 3)
Title: Snow Falling on Cedars
Author: Guterson, David
ISBN: 067976402X
Price: 11.20
Number Remaining: 1

*******************************************************************
Select an operation:
1: Add a Book
2: Delete a Book
3: Purchase a Book
4: Search for books by author
5: Quit
> 1
Enter the title of the book: The Bean Trees
Enter the name of the author: Kingsolver, Barbara
Enter the ISBN: 0061097314
Enter price: 7.99
Enter number in shipment: 4
Inventory:
(1 of 4)
Title: The Poisonwood Bible
Author: Kingsolver, Barbara
ISBN: 0060930535
Price: 10.50
Number Remaining: 4
(2 of 4)
Title: She's Come Undone
Author: Lamb, Wally
ISBN: 0671021001
Price: 7.99
Number Remaining: 12
(3 of 4)
Title: Snow Falling on Cedars
Author: Guterson, David
ISBN: 067976402X
Price: 11.20
Number Remaining: 1
(4 of 4)
Title: The Bean Trees
Author: Kingsolver, Barbara
ISBN: 0061097314
Price: 7.99
Number Remaining: 4

*******************************************************************
Select an operation:
1: Add a Book
2: Delete a Book
3: Purchase a Book
4: Search for books by author
5: Quit
> 3
Enter the book number: 3
Title: Snow Falling on Cedars
Author: Guterson, David
ISBN: 067976402X
Price: 11.20
Number Remaining: 0

*******************************************************************
Select an operation:
1: Add a Book
2: Delete a Book
3: Purchase a Book
4: Search for books by author
5: Quit
> 5
Enter file name: inventory.txt
Saved...

Hints

  1. You should include the string.h library so that you can use the string comparison and manipulation functions. See page 433 of your text for a list of string functions.
  2. The function strcmp will only return 0 if the strings are EXACTLY the same.
  3. To make your delete and print functions easier to implement, modify your print function to print out a number associated with each book as shown above. For example, print (1 of 3) above the first book in an inventory of 3.
  4. Use gets to read a string containing spaces from standard input. To ensure that the string you read from the keyboard does not include the newline character, you will need to do something similar to the following (see page 444 of the text):
    if(line[strlen(line) - 1] == '\n') {
      line[strlen(line) - 1] = '\0';
    }
  5. Make sure all of your functions perform all necessary error checking. For example, a user cannot add a new book if the number of books in the inventory is 50.

Extra Credit Opportunity

  1. Make sure that each function is well documented.
  2. Make sure a lab assistant (Dianne or I) has seen your program run. I will schedule additional lab times during the final exam period for this purpose.
  3. Copy and paste the output of your program to the bottom of your program itself. Make sure the output is a comment. That means, put a /* before the output and a */ after the output.
  4. Make sure all of your functions perform all necessary error checking.

Sami Rollins