CSCI 131 - Techniques in Programming, Spring 2014

    Home | | Schedule | | Assignments | | Lectures | | Resources

    Project Five Specifications

    Nile.com

    Due Date: Friday, May 2, at 10:00 a.m.

    NOTE: Read through the project description below, but before you begin implementation, make sure to read the specifications for the project check that is due on April 25.

    Introduction. This project familiarizes you with the recently taught data types such as strings, structs, classes, arrays of structs, arrays of classes and their input and output to and from files. This project will be taking you much closer to "real world" applications. Your program will handle several functions that might be performed by a program for an on-line store such as Amazon.com (although those programs are not normally written in C++). The function main( ) and associated functions will be written in a file named proj5.cc. In addition, a library of functions written to manage the inventory and orders will be written in the file orders.cc and the associated header file will be orders.h. Finally, there is a customerRec class that is defined in the header file customerRec.h and implemented in the file customerRec.cc.

    Overview. You have just been hired (stock options and all) to work for the newly formed dot-com company, Nile.com. Although it is now in its infancy, the founders fully expect it to grow, and as the name implies, someday rival the mammoth internet store, Amazon.com. Unfortunately, the server has crashed, and they need you to create a new program to manage new orders and keep track of the names and addresses of customers who are ordering each item. You need to work quickly so that they can get back to selling those classic books, CD's, videos and games, such as the CD from that well known group, "The fully dressed ladies" and the hot new game of trivia and easy money, "Trivial Millionaires".

    In brief, you need to set up an program that displays an interactive menu that offers a choice between four tasks. The first task lists the items for sale along with their price and the number currently in stock. The second processes the requests of customers to purchase one or more items. If there are enough items in stock, the customer's name is added to a list of customers to receive that item. If there are not enough items, the customer's name is added to a list of people waiting for back-orders of goods. The third task creates a file containing the current information about each item in the inventory, including the names and addresses of all customers who have successfully ordered that item. The fourth task creates a different file with a list of all the customers waiting for back-ordered items. Your new boss has informed you that the information about all the items currently in stock (including price, number in stock, etc.) has been saved on a separate disk, so it is available for your program to read in.

    Specifications:
    1. Placement of functions.
    All constant definitions, typedefs, and function prototypes have been provided in a header file named orders.h. Do not forget to include this header file in both proj5.cc and orders.cc. Also, orders.h includes the file, customerRec.h, which includes the class definition for the customerRec class. The customerRec.h file has also been provided for you.

    Some of the constants, typedefs and structs, listed in the orders.h file are provided for you to use. An electronic copy of these files can be found in the directory,

      ~csci131/PROJECTS/PROJ5/.

    If you copy all the files from this directory, you will get, among other things, copies of orders.h and customerRec.h. You may not change any of this code, but you should complete it with your own function prototypes, documentation or anything else you deem appropriate.

    2. Implementation of CustomerRec class member functions.
    The CustomerRec class has several member functions, listed in customerRec.h. Some of these functions (the default constructor, GetName( ) and GetAddress( ) have been implemented for you in the file customerRec.cc. You need to implement the other member functions, including a constructor that provides parameters for the initialization of the name and address, SetName( ), SetAddress( ) and Write( ). If you are uncertain how to do this, review the class function in lab 8.

    3. Local variables in main( )
    In the main() function, you will need to declare arrays for the list of items in the inventory and for the list of customers with backorders. For example, you may declare the following:

    	int             numItems = 0;
    	Inventory       itemList;
    	int             numBackOrders = 0;
    	BackOrderList   backOrders;
    

    Note that these will have to be passed as parameters to several functions. Do not make these global variables.


    4. The main() function.
    The purpose of the main( ) and associated functions in proj5.cc will be 2-fold. First, it should read in the current inventory information from a file named proj5.dat, and then it will display a menu of choices for the user. Once the user has selected a choice, the appropriate function (which should be included in the file orders.cc) will be called to handle that choice.

    a) Reading in the data: The main( ) program should call a function, ReadInventory(), to read in data from proj5.dat. The prototype for ReadInventory( ) is in orders.h. It should take two parameters: an integer to keep track of the number of items you read in, and an Inventory in which you should store the items you read in. You should implement ReadInventory( ) in the orders.cc file.

    There is a sample proj5.dat file in the ~csci131/PROJECTS/PROJ5 directory that you should use to test ReadInventory( ). The information should be read into the array, itemList, until the end of the file is reached. Keep a running count of how many items are for sale in the variable called numItems. The information for an item occupies 4 lines. One line for the name, one for the price, one for the type of item (e.g. Book, CD, Game, etc.) and the final line for the number of items currently in stock. Here is an example:

    The bold and the ugly
    26.94
    Book
    27
    

    As you read in each item, you should take the opportunity to initialize the numCustomers and the numOrdered data members of each element of the Inventory array. You should initialize these data members to zero. Otherwise you will have to write separate code to loop through the inventory and initialize these values.

    When all the items have been read in, and you have performed all other necessary initializations, close the file and report to the user the completion of data input and the number of items available in the inventory. The message should look like this (although the number of items will depend on how many there are in the input file):

      Inventory has been read.
      There are currently 6 items for sale.
      

    Note that the correct functioning of much of the rest of the project depends on the file being correctly read in and stored. You are strongly encouraged to write and debug this part of the code first (perhaps in conjunction with the code to print out the inventory list) before proceeding with the rest.

    b) Displaying the menu: Once the data is read in, the main( ) function should display a menu with the various options. (You might want to write a separate function to display the menu. This is good programming technique--dividing your code into subtasks performed by separate functions). Your program should then prompt the user to enter a choice (don't forget to echo print). It then calls the appropriate function to perform the task corresponding to that choice. The options provided in the main menu are the following:

      (L)  Print a list of the items for sale.
      (P)  Process a customers purchase requests.
      (I)  Create a file with the current inventory status.
      (B)  Create a file with customers waiting for backorders.
      (Q)  Quit.
      

    The user continually chooses a function by typing the corresponding character, until Q is entered, at which point the program exits. The menu should be reprinted on the screen between different choices. If some selection other than an acceptable one is typed by the user, the user must be informed of the error and then asked to respond to the menu again until he/she enters a valid response. (The response should be accepted if the user response with either the uppercase or the lowercase form of the character).

    5. The ( L ) option:
    The choice of ( L ) is used for printing a list of the current items for sale, along with information about the category of the item, its price and the number currently in stock (all information from the struct ItemInfo from the array itemList). You should write a function, PrintInventory( ) that prints out the information. The information should be printed to the screen in the following format:

    PRODUCT TITLE             CATEGORY      PRICE   NUMBER IN STOCK
    The bold and the ugly     Book          26.94        27
    The fully dressed ladies  CD            12.37        34
    My Lunch with Andre       Video         19.99         1
    

    6. The ( P ) option:
    When the user chooses ( P ), the program should call a function, ProcessPurchases( ) that handles a customer's request to make purchases. As the user makes each purchase, the information about the purchase will be stored in an array (local to this function) of type RequestRec. Thus, you will want to declare a local variable to store this information:

      ShoppingList shopping;

    The function will begin with a prompt for the user to type in information for creating a CustomerRec object. Thus, the function will ask the user to type in her name, then it will ask for her address. These should both be recorded in a locally declared object variable of type CustomerRec, using the appropriate member functions of the CustomerRec class. The function will then ask the user if she would like to make a purchase. If the answer is yes, it will prompt her to enter the name of the item she wants to purchase. (Do not forget to echo print).

    Your function should then search the array, itemList, to determine whether the item requested is one of the items for sale. If the item is not found, an appropriate error message should be given, and the user again asked if she would like to make another purchase.

    If the item is found, the user should be asked for the quantity she would like to purchase. This information, along with information about the customer's name and address, the item's name and price should be stored in the current element of the array, shopping.

    In addition to updating the ShoppingList, the itemList entry for the item requested should be updated to increase the numOrdered member by the amount the customer has ordered. If the updated number ordered is more than the number of items in stock for this item, the customer should be informed that the item is back-ordered and there will be a delay in delivery. The current RequestRec should be added to the list of requests that are backordered (the array, backOrders). Don't forget to update the number of back-orders. The item should remain on the customer's shoppingList.

    If the updated number of items ordered is still less than or equal to the number of items in stock, the current RequestRec should be added to the customers array that is part of the requested item's ItemInfo struct, and the numCustomers should also be updated.

    Regardless of whether or not the item is back-ordered, the user should be informed of the purchase and the total price for that purchase:

      You have ordered 2 copies of The fully dressed ladies.
      Unit Price: 12.37   Total Price: 24.74
      

    After processing a purchase request, the user should then be asked whether she wishes to make another purchase. If so, the above process should be repeated, starting with a prompt to enter the name of the item. If the user responds that they do not want to make another purchase, the function should print out (to the monitor) a list of the items ordered, along with the quantity and unit prices and the total price of the entire purchase (this list should include back-ordered items as well):

      Customer Order: 
      Name: Annie Hall
      Address: 1212 New York Ave, New York, NY  01111
      
      ITEM                       PRICE   QUANTITY   TOTAL
      The fully dressed ladies   12.37          2   24.74
      The bold and the ugly      26.94          3   80.82
      
      Total Cost = 105.56
      

    Following this report, the control should return to the main( ) function and the menu should be re-displayed.

    7. The ( I ) option.
    The choice of ( I ) should call a function, InventoryStatus( ), that opens an output file called inventory.dat. The function should write most of the information in the itemList database into this file. Specifically it should list each item name, price, number in stock and number ordered. It should also list all the customers and their addresses for each order. Note that if a single customer orders more copies than are currently in stock, that customer's name will be included on the list of backorders, rather than in the customer list for the item. In this case, the file will show that some orders have been made, but no customers will be listed (they will be listed in the file of backorders).

    Entire Inventory database Listing
    
    Item: The bold and the ugly     Price: 26.94
    Number in stock: 27             Number ordered: 6
    
       Name and Address                                 Quantity
    1  Annie Hall                                          3
       1212 New York Ave, New York, NY  01111
                   
    2  George Shaw                                         3
       3434 Pygmalion Circle, Fair City, CA, 94111       
    
    Item: The fully dressed ladies  Price: 12.37
    Number in stock: 34             Number ordered: 2
    
       Name and Address                                 Quantity
    1  Annie Hall                                          2
       1212 New York Ave, New York, NY  01111
                   
    Item: My Lunch with Andre       Price: 19.99
    Number in stock: 1              Number ordered: 2
    
    Item: The March Hares           Price: 15.33
    Number in stock: 5              Number ordered: 0
    

    After the completion of the report, notify the user that it is done, close the file and return to main().

    8. The ( B ) option.
    The choice of ( B ) should call yet another function, BackOrderStatus( ) that opens a different output file named backOrders.dat. The function should write out the list of customers waiting for back-ordered items as recorded in the array of RequestRecs, backOrders. The output in that file should have the following format:

    There are 2 customers waiting for back-ordered items.
    1  Name:            George Shaw
       Address:         3434 Pygmalion Circle, Fair City, CA, 94111
       Item:            My Lunch with Andre
       Number ordered:  2
    
    2  Name:            Annie Hall
       Address:         1212 New York Ave, New York, NY 01111
       Item:            Brahms Lullaby
       Number ordered:  5
    

    After the completion of the report, notify the user that it is done, close the file and return to main().

    9. Location of functions.
    Write the prototypes for ReadInventory( ), PrintInventory( ), ProcessPurchases( ), InventoryStatus( ), and BackOrderStatus( ) in the file, orders.h. Implement these functions in the file, orders.cc. Note that all of these functions will require parameters (most of which are not listed in the descriptions above).

    Program testing: As you write your program, you can test it along the way by compiling and running it by itself. You can compile your program using the command:

      g++ -g -Wall proj5.cc orders.cc customerRec.cc -o proj5
      

    You can then run it by typing, proj5.

    When you have finished your program, you can test it more thoroughly using the test5 program. The directory ~csci131/PROJECTS/PROJ5 contains, among other things, files named proj5.dat, terminal.inp and test5. Copy these files into a directory which also contains your proj5.cc, orders.cc and orders.h, customerRec.h and customerRec.cc. Then type test5. The test5 script will compile your program and run using the commands from terminal.inp and the inventory data in proj5.dat. The terminal output from this test run will be placed in a file named output5 and the files, inventory.dat and backOrders.dat (created by your program). You can compare your output with the files model5.out, model.inventory and model.backOrders in the ~csci131/PROJECTS/PROJ5 directory.

    To submit your finished project:
    1. Submit your program file electronically in the directory which contains your (presumably thoroughly tested) proj5.cc, customerRec.cc, customerRec.h orders.cc and orders.h. (The submit program will not accept a program that does not compile).

    2. Hand in a hard copy of the files you submitted electronically. Hand this to your instructor in class on the project's due date.

    3. Print out the grading header, put your name at the top of it, and hand it in with your hard copy.

    Get started early and have fun!

    Honor code: Please review the collaboration policy on the main course webpage. Also refer to the math and CS department honor code policy.


    Home | | Schedule | | Assignments | | Lectures | | Resources



    Computer Science 131
    Last Modified: April 13, 2014
    Page Expires: September 30, 2014