Project 3

For this project we are going to be working with arrays and structures along with a little file I/O thrown in for good measure. Of course, we'll still be using sequence, selection, iteration and functions.

Details

The main idea of this project is to create a basic inventory system. It will store a maximum of 25 items of stock. The items will have the following fields:

  1. A Name - The name will be a single word: e.g. ball, widget1, etc.
  2. A description - The description will describe the item. It can have spaces but will be terminated with a newline (\n) character
  3. A part number - the part number will uniquely id the item. It will be a single word: e.g. Item-1, part#3, etc.
  4. A cost - the cost is how much the item costs: e.g. $1.34, or $1.00, it will always have a dollar sign ($) and a decimal (.)
  5. A quantity - how many of these suckers do we have in stock. This will be an integer.

The function you need to write needs to be declared in a header called inventory.h and the primary function you need to write is void inventory( istream& in, ostream& out );

You will create a struct that will contain the parts of the item or widget. Then you will create an array of your stucts to store the inventory items. Your program will then interpret a series of commands to manipulate the stock. The commands are as follows:

  1. list
  2. add
  3. buy
  4. save

There is one implicit command. The first line in the command istream will be

filename: input.txt
where input.txt will be the name of the input file you are to open and read. The input file will have a set of "widgets" listed in it. You are to store as many as you can before either the file is all read or you have stored you max of 25. The format for the file will use the same format as the add command.

After you read each command we are going to have the output: Command: <command> - where <command> is the command you read in. That will make the output easier to follow.

More details for the commands are here

list

list
The list command comes in two flavors. 1. list - list on a line by itself means to list all of the stock onto the ostream that is given to the primary funciton. 2. list - list followed by a space then followed by a part number means to just list that part number item onto the ostream. The output for this command can be long. It would have the following format for each widget that is listed:
Widget: MyWidget
Description: This describes MyWidget
Part #: Part-1
Cost: $1.32
Quantity: 2

This assumes that the widget has the proprieties listed. If this was just list, then all the widgets would be listed in this manner.

If the list is followed by a part number and that part number is not in your list of widget then use this output:

Sorry, we don't have Part-1 in stock.\n

Assuming that Part-1 was the part that was asked to be listed: e.g. list Part-1\n

add

add The add command can do two things. 1. If the part number for the part is found in the current inventory list, then the quantity is added to the part in stock. 2. If the part number for the part is not found in the current inventory list, then the whole new item is added to the list, if there is space. Add has the form

add
Widget: MyWidget
Description: This describes MyWidget
Part #: Part-1
Cost: $1.32
Quantity: 2

This command has no output other then the echo of the command

buy

buy
The buy command attempts to buy a stock item from your stock list. Buy has the form
buy 
Part #: Part-1 100

The output for this command is as follows:

Purchased:\n
Part #: Part-1\n
Cost: $1.50\n

This assumes that the part was in stock, it has part # Part-1 and the total cost to purchase is $1.50. If the part is out of stock, then you have this ouptut:

Sorry, we don't have Part-1 in stock.\n

This assumes that the part number that was attempted to be purchased was Part-1. The part would match the part that was attempted to be bought.

save

save
Save will then provide a filename. This is the file to be used for writing the stock to. Save has the form
save myFile.txt

There is no output except that the file is "saved" to the given file name. The format should match the format for the loading. That is, if you save a file, you should use the same format so you can load it at the start of a program.

Input/Output

Since this project has a lot of various types of input and output I will be putting sample input and output in files. I'll be linking them here soon, so check back.

Checking back, here's 1 sample zip file for you to use. The inventory.txt is the list of widgets to read. The commands is the commands for the input stream and the output is the results.

Due

This project is due Wednesday November 5 by 11:55PM

Grading

Like our other projects Web-CAT will be used for grading for 75% of the grade. The TAs will be looking for the rest of the requirements as listed below

Requirements

  1. Comments on your variables, function headers and other comments as needed
  2. Your function must be declared in a header file called inventory.h
  3. You must write the primary function with signature void inventory(istream& in, ostream& out );
  4. Each of the commands above must be implemented as a function.
  5. Other functions are highly encouraged.
  6. You may not use vector or other STL data structure instead of the array. You must use an array.
  7. You must use a struct for the items/widgets.