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.
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:
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:
There is one implicit command. The first line in the command istream will be
filename: input.txtwhere 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
listThe 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
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 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
buyThe 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.
saveSave 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.
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.
This project is due Wednesday November 5 by 11:55PM
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
inventory.h
void inventory(istream& in, ostream& out );