Programming Assignment #4

Due: Thurs, March 6

Objective

Upon completion of this program, you should gain experience in working with dynamic arrays of objects, as well as working with two classes in a "has-a" relationship. This will also give some extra practice with array and c-string usage.

Task

You will be writing classes that implement an inventory list simulation for a bookstore.  The list will be a dynamic array of Book objects, each of which stores several pieces of information about a book.  You will need to finish the writing of two classes:  Book and Store.  The full header file for the Book class has been provided in a file called book.h.  You can get a copy of it here.

Program Details and Requirements

1) Using the Book class declaration, write the book.cpp file and define all of the member functions that are declared in the file book.h.   (Do not change book.h in any way.  Just take the existing class interface and fill in the function definitions).  Notice that there are only four genres of books in this class:  FICTION, MYSTERY, SCIFI, and COMPUTER.  The expected functions behaviors are described in the comments of this header file.
 

2) Write a class called Store (filenames are store.h and store.cpp).  A Store object should contain at least the following information:  the amount of money in the store cash register and a book inventory list.  There is no size limit to the inventory list, so it should be implemented with a dynamically allocated array.  (This means you'll need an array of Book objects).  You can add any public or private functions into the Store class that you feel are helpful.  In addition to the Store class itself, you will also create a menu program to manage the inventory of books.  However, the Store class will be able to do much of the work, as the Store member functions will be the interface between the menu program and the internally stored data (cash register and list of books).

Rules for the Store class:

3) Write a main program (filename menu.cpp) that creates a single Store object and then implements a menu interface to allow interaction with the object.  The program should begin by asking the user to input the starting amount of money in the store's cash register (as a double).  This should be stored in the Store object.  Your main program should implement the following menu loop (any single letter options should work on both lower and upper case inputs):

  A:   Add a book to inventory 
  F:   Find a book from inventory 
  S:   Sell a book 
  D:   Display the inventory list 
  G:   Genre summary 
  M:   Show this Menu 
  X:   eXit the program 

Behavior of menu selections:

Always ask for user input in the order specified.  Remember, all user inputs described in the menu options below should be done by the menu program (not inside the Store class). Such input can then be sent into the Store class -- the Store class member functions should do most of the actual work, since they will have access to the list of books and the cash register. For all user inputs (keyboard), assume the following:

A:  This menu option should allow the adding of a book to the inventory list.  The user will need to type in the book's information.  Prompt and allow the user to enter the information in the following order:   title, author, genre, price.  The information should be sent into the Store object and stored in the list of books.

F:  This option should allow the user to search for a book in the inventory list by title or by author.  When this option is selected, ask the user to enter a search string (may assume user entry will be a string 30 characters or less).  If the search string matches a book title, display the information for that book (output format is described in the Display function of the Book class).  If the search string matches an author in the list, display the information for all books by that author.  If no matching books are found, display an appropriate message informing the user.

S:  This option should allow a sale to be made.  When this option is selected, ask the user to type in the title of the book (you may assume that book titles in the list will be unique).  Remove this book from the inventory list, and since it is being purchased, add the purchase price into the store's cash register.  If there is no such title, inform the user and return to the menu.

D:  This option should simply display the entire inventory list, one line per book, in an organized manner (like a table).  Each line should contain one book's information, as described in the book.h file.  Also, display the total number of books in the inventory list, as well as the current amount of money in the store cash register.

G:  This option should list the inventory contents for one specific genre.  When this option is selected, ask the user to input a genre.  For the category selected, print out the contents of the inventory list, as in the Display option, but for the books matching the selected genre only.  (e.g. list all of the Mystery books).  After this, also display the total quantity, as well as the total cost (the sum of the prices), of the books in this genre.

M:  Re-display the menu.
X:  Exit the menu program.  Upon exiting, print out the final amount of money in the store cash register.
 

5) General Requirements:

Extra Credit:

Write a function called "Sort", and add in a menu option (using the letter 'O') for sorting the inventory list.  When this menu option is chosen, ask the user whether they want to sort by author or title (enter 'A' or 'T', allowing upper or lower case).  Then, sort the inventory list by ascending alphabetic (or actually, lexicographic) order, on the appropriate field (author or title).

Submit the following files through the web page in the usual manner:

  book.cpp 
  store.h 
  store.cpp 
  menu.cpp 

You can run my version of the menu executable from linprog.cs.fsu.edu with the command:

  ~myers/copprog/menu4