CPS 6: Assignment 6

Summer 1999

Fish Store Inventory

Due Friday: June 18, 11:59pm

15 points

Change into your cps6 directory and create a directory called "assign6". Change into the "assign6" directory. In order to do this assignment, you need to copy files using the following "cp" command (don't forget the trailing period, or dot). Type:

 cp  ~dr/cps6/assign6/*   .

If you type "ls" you should see "Makefile", "fish1.inv", "fish1.sale", "fish2.inv", "fish2.sale", "gwindow.h", "gwindow.cc", "inventory.h", "inventory.cc", and "fishinv.cc".

For the programming problem that follows, you should use the style rules discussed in class, which includes meaningful variable names, indentation, and comments at the top of the file and for each function.

Problem: Fishy Business

Suppose that you have a part time job at an aquarium store. You notice that the owner Eddie throws all the receipts in a box, and then processes them by hand once a week to determine what to reorder. You decide to impress your boss by writing a program that will process the receipts, and produce a picture showing the items that are currently in stock and the items that need to be reordered. Your boss is impressed so he tells you to quit cleaning fish tanks and to start work on the program.

Getting Started

In this assignment, you'll use the Inventory class to manage the inventory of the store, a Vector to store the information (name, quantity, etc.) for each item in the store, and the Window class to draw a histogram picture of the inventory.

A Sample Run: Using Samba

NOTE: This doesn't show anything until you create an Inventory variable. Declare a variable of type Inventory in the main function in fishinv.cc, then try this out.

Let's compile the program and see how to run it. Compile the program fishinv.cc by typing: make fishinv (Note that you may get a fair number of WARNINGS when you type "make" troughout this assignment. Usually these warnings can be ignored.)

We'll be using the Samba animator to display the picture. The animator will only work under X windows; any of the Sparc 5's should work fine.

To use the animator, you should have first compiled fishinv.cc above. The Inventory and Window class output animator commands that are understood by the Samba animator. To run your program, type:

          fishinv  | samba

Go ahead and run the program now. An Samba window should appear. You might need to move the Samba window so you can see it and the other windows at the same time. To start the animation, click on the button start . To quit at any time, click on the quit button. Not much happens at this point, you should see a line drawn.

The animator is set to run on high speed. The Polka window has a speed control bar which is currently set on the highest speed. You might want to slow the animation down until your program is correct, so you can see how the picture is drawn. Move the rectangle in this column to midway to slow the animation down before clicking the start button.

IMPORTANT NOTE: All output is being sent to the animator. If you want to print anything to the screen (for debugging purposes or otherwise) you'll need to print the word comment at the beginning of each output line and put an endl at the end of each line output. That is, each cout statement in your program should start and end with:

    cout << "comment " << .... << endl;

The Inventory Class

The Inventory class will store lots of information about each item that can be bought at the fish store. The private section of inventory.h includes the following declarations:

   Window myPicture;           // graphic window variable
   Vector <FishInfo> myList;   // inventory of items in store
   int myNumItems;             // number of items in myList
   int mySize;                 // max capacity of myList

The variable myPicture is a graphic window that will be used to display the histogram. The variable myList is a vector of type FishInfo. FishInfo is a struct with several parts.

struct FishInfo
{
   string name;         // name of item
   int nameident;       // tag for name displayed
   int quantity;        // quantity of items; if negative, items on order
   int ypos;            // y position to display this item and its points
   Vector<int> tag;     // array of tags for marks
};

For each item in the store, we'll keep track of its name and current quantity. The name will be displayed in the picture using the Text function from the Window class. The Text function returns a unique number, which will be stored in the variable nameident. Each item will be drawn in the picture at a different y-position. The y-positions for each item have already been calculated for you and stored in the variable ypos.

If an item has quantity X, then X marks will be drawn in the picture. Later, when transactions are processed, the quantity may increase or decrease. If it decreases, then you'll have to remove some of the marks. Marks are drawn as points using the Window class function Point. Remember that each object drawn in the Window class has a unique number (or tag) associated with it. This tag can be used to change it's color, hide it, etc. For every mark created in the picture, you will have to save the tag associated with it in case later you have to remove the mark. Thus, each item will have a vector called tag that can hold the unique tags for up to 100 marks, which will be the largest quantity possible.

Thus myList is a vector where each item in the vector contains several parts, one such part is another vector, tag.

Part 1: Initial Setup and Processing files

In this part, you will create an Inventory and read in the data. The data for this program comes in two files. One file has the original inventory (filename ends in .inv). Each line contains the name of an item (one word with no blanks) and a nonnegative integer containing the quantity. A small sample inventory file is shown below. The lines show that there are two inventory items, discus and catfish. There are currently 6 discus fish and 0 catfish.

 
  discus 6
  catfish 0

Two sample inventory files have been provided for you, fish1.inv (smaller) and fish2.inv. You should make sure the program works for the smaller file before testing the larger file.

A second file provides transaction information about the inventory and may contain new inventory items (filename ends in .sale). Each line contains three items: the name of the item (one word with no blanks), the quantity (nonnegative) involved in the transaction, and the type of the transaction (bought or sold). Items sold decrease the current inventory (or make it negative if items are on backorder), and items bought increase the inventory. In the sample transaction file shown below, 3 discus were sold, 4 catfish were bought, and 2 angelfish (a new item in the inventory) were bought.

 
  discus 3 sold
  catfish 4 bought
  angelfish 2 bought

Two sample transaction files have been provided for you, fish1.sale (smaller) and fish2.sale.

Make the following changes in the file fishinv.cc.

Compile your program and run it to make sure that it is correct. Run it with fish1.inv and fish1.sale as input. The only thing added to the picture at this time is the title. Currently, almost all output is being sent to the xterm.

Part 2: Processing the Inventory

Make the following changes to the program.

Compile your program by typing make fishinv and run it by typing fishinv | samba

If you use the datafiles fish1.inv and fish1.sale, then click here to see what the picture should look like. The name of your fish store may be different. If you use the datafiles fish2.inv and fish2.sale, then click here to see what the picture should look like.

Part 3: Processing Transactions

Make the following changes to your program.

Compile your program by typing make fishinv and run it by typing fishinv | samba

If you use the datafiles fish1.inv and fish1.sale, then click here to see what the final picture should look like. If you use the datafiles fish2.inv and fish2.sale, then click here to see what the final picture should look like.

NOTE: Make sure your histogram is dynamically updated. That is, the picture should be updated after each transaction. Waiting until all transactions have been processed and then displaying the final picture will not receive full credit.

EXTRA CREDIT: (4 pts total)

If you do any extra credit, make sure you put a note in your README file mentioning that you did the extra credit.

Modify your program in the following manner.

Submitting Programs

When all your programs compile and produce the correct output, create a "README" file (please use all capital letters). Include your name, section number, the date, and an estimate of how long you worked on the assignment in the "README" file. If you did the extra credit, mention this. You must also include a list of names of all those people with whom you consulted or received help from on the assignment. See the CPS 6 syllabus for the rules on consulting.

To submit your programs electronically type:

    submit6 assign6 README fishinv.cc inventory.cc inventory.h

You should receive a message telling you that the programs were submitted correctly.