The office inventory
Problem description
Write a program to maintain and report an inventory of office supplies. The program should start from a zero inventory and be able to accept input in the form of a description and an amount by which to increase or decrease (if negative) the holding of the supply item. The cost of each supply item is constant and is hard-coded in the program. At the end of the input, a list of supply items, their amounts and the total money worth of the inventory should be printed.
Procedure
Follow these steps to end up with a sucessful program:
- Write a one sentence problem statement.
- Write the problem description, as given above.
- Do the analysis for object design, ending up with at least three classes (including a class for the application), choosing suitable representations for the class members. Write the object design down.
- Do the analysis for process design, adding suitable function members to your classes with appropriate parameters. The application class with have (at least) a function member
run
.
- Write C++ program code from your analysis in 3 and 4.
- Create a source file using the editor.
- Compile the source code using g++.
- The program should create an "empty" inventory that can handle the following supply types, listed here with their unit cost:
pencils $0.30
legal-pads $1.20
paper-clips $0.02
folders $0.03
pens $1.35
- Deliverables:
- your design document with its four sections: problem statement, problem description, object design and process design.
- your source code, suitably commented and with good layout
- the output produced by the program with the following input sequence:pencils 100
legal-pads 25
paper-clips 500
folders 250
pens 25
pencils -12
folders -53
pens -17
pencils -50
legal-pads -10
pencils 60
pens 10
pencils -14
- your source code e-mailed to the grader, login name salahmed.
Notes and hints
- Keep your classes to the minimum necessary (but at least three in total)
- Keep the member representations as simple as possible. You do not need anything more fancy than base types, one vector, and the string type (see the handout on the book collection).
- Keep all data private: use accessor functions to selectively open up access to other classes. Don't use global variables!!
- use this control structure for reading in your inventory change:
read info
while (!cin.eof()) {
process info.
read more info.
}
This give the correct behavior for end of file.
- end of input on UNIX is signalled by typing ctrl-D on a line by itself (ctrl-Z in DOS)
- prompt the user for input
- display screen output with reasonable layout, taking note of the display of money values. Use the setiosflags, setprecision and setwidth manipulators on the cout object to do this. See pgs. 216-220 for examples. You will need the ios::showpoint flag to ensure that whole numbers of dollars are shown with zero cents after the decimal point.
- use cin and cout, not printf and scanf
- when you are ready to produce the final output of the program, redirect the standard output produced by
cout
into a file by typing:
a.out > outputfile
which you can then print on the lineprinter.
- mail your source code with:
mail salahmed < filename.cc