This project involves designing and creating a C++ program that will utilize the InventoryItem class. (The InventoryItem.h source code for this class is provided) Your program must not modify the class specification for the InventoryItem class.
The program must be organized as a "Command Loop" program. The program must implement the following interactive commands:
a Add parts: increase the units value for an existing inventory item.
h print Help text.
i Input inventory data from a file.
n create a New inventory Item.
o Output inventory data to a file.
p Print inventory list.
q Quit (end the program).
r Remove parts: reduce the units value for an existing inventory item.
(Specific requirements for each command are stated in the Requirements for Interactive Commands section of this document.)
The program must create an array of 100 InventoryItem objects (or a vector of InventoryItem objects).
Command i
Input Inventory Data from File:
Command n
Create a New Inventory Item:
Command o
Output Inventory Data to File:
Command p
Print Inventory Data to Screen:
Output the contents of the InventoryItem array (or vector) to the screen. (Refer to the Sample Output section of this document for formatting examples.)
Command q
Quit (exit) the Program
Command r
Remove Parts from Existing Inventory Item:
The "input" / output commands read / write data that is in a pipe-delimited text file.
The format of each line of text, in the data file, is described below:
inventory item number | description | cost | units
Explanation of Data Fields
When reading the data file, your program needs to read one line of text from the file at a time, break each line of text into separate fields, and convert each field to the correct data type.
Four sample input files are provided: electrical.txt, fasteners.txt, miscellaneous.txt and plumbing.txt. The data files that your program creates must obey the same file format as these sample files. The program must work correctly with these files, as well as general files of similar format.
electrical.txt
0|Cable|5.00|18
1|Extension Cord (14/3, 25 ft)|27.95|6
2|Light switch (15 amp)|2.79|10
3|Ceiling Fan (52 inch)|79.95|3
4|Vinyl Electrical Tape (20 ft roll)|0.79|30
5|GFI Tester|9.35|5
fasteners.txt
0|Turnbuckle|3.80|25
1|Siding nails (box of 100)|4.00|20
2|Flat washer (box of 100)|2.80|30
3|Machine screw (box of 100)|3.20|10
4|Hex bolt (box of 100)|6.50|23
5|Hex nut (box of 100)|3.80|15
6|Sheet Metal Screw (qty 100)|1.50|28
miscellaneous.txt
0|Door Hinges (3-pack)|6.30|10
1|Rubber work boots (1 pair)|28.00|5
2|Leather Work Gloves (1 pair)|12.00|8
3|Long Handle Grass Shear|30.00|5
plumbing.txt
0|Pump|39.00|20
1|Gasket|1.50|29
2|Water Level Guage|12.99|30
3|Faucet Repair Kit|4.89|8
4|Teflon Thread Seal Tape (50 ft roll)|3.30|12
5|shutoff valve|6.50|10
In the sample data on the next several pages, what the user types is shown in bold. In actuality, what the user types would have the same text format as the rest of the output.
Command: h
Supported commands:
a Add parts.
h print Help text.
i Input inventory data from a file.
n New inventory Item.
o Output inventory data to a file.
p Print inventory list.
q quit (end the program).
r Remove parts.
Command: i
Enter name of input file: plumbing.txt
6 records loaded to array.
Command: pItem Num Description Cost Quantity
-------- ----------- ---- --------
0 Pump 39.00 20
1 Gasket 1.50 29
2 Water Level Guage 12.99 30
3 Faucet Repair Kit 4.89 8
4 Teflon Thread Seal Tape (50 ft roll) 3.30 12
5 shutoff valve 6.50 10
6 records.
Command: i
Enter name of input file: electrical.txt
6 records loaded to array.
Command: pItem Num Description Cost Quantity
-------- ----------- ---- --------
0 Pump 39.00 20
1 Gasket 1.50 29
2 Water Level Guage 12.99 30
3 Faucet Repair Kit 4.89 8
4 Teflon Thread Seal Tape (50 ft roll) 3.30 12
5 shutoff valve 6.50 10
6 Cable 5.00 18
7 Extension Cord (14/3, 25 ft) 27.95 6
8 Light switch (15 amp) 2.79 10
9 Ceiling Fan (52 inch) 79.95 3
10 Vinyl Electrical Tape (20 ft roll) 0.79 30
11 GFI Tester 9.35 5
12 records.
command: a
Choose a Item Number: 7
How many parts to add? 5
Command: pItem Num Description Cost Quantity
-------- ----------- ---- --------
0 Pump 39.00 20
1 Gasket 1.50 29
2 Water Level Guage 12.99 30
3 Faucet Repair Kit 4.89 8
4 Teflon Thread Seal Tape (50 ft roll) 3.30 12
5 shutoff valve 6.50 10
6 Cable 5.00 18
7 Extension Cord (14/3, 25 ft) 27.95 11
8 Light switch (15 amp) 2.79 10
9 Ceiling Fan (52 inch) 79.95 3
10 Vinyl Electrical Tape (20 ft roll) 0.79 30
11 GFI Tester 9.35 5
12 records.
Command: r
Choose a Item Number: 9
How many parts to remove? 5
Error: You are attempting to remove more parts than the Item currently holds.
Command: r
Choose a Item Number: 9
How many parts to remove? 3
Command: pItem Num Description Cost Quantity
-------- ----------- ---- --------
0 Pump 39.00 20
1 Gasket 1.50 29
2 Water Level Guage 12.99 30
3 Faucet Repair Kit 4.89 8
4 Teflon Thread Seal Tape (50 ft roll) 3.30 12
5 shutoff valve 6.50 10
6 Cable 5.00 18
7 Extension Cord (14/3, 25 ft) 27.95 11
8 Light switch (15 amp) 2.79 10
9 Ceiling Fan (52 inch) 79.95 0
10 Vinyl Electrical Tape (20 ft roll) 0.79 30
11 GFI Tester 9.35 5
12 records.
Command: o
Enter name of output file: testData01.txt
12 records written to file.
Command: i
Enter name of input file: testData01.txt
12 records loaded to array.
Command: pItem Num Description Cost Quantity
-------- ----------- ---- --------
0 Pump 39.00 20
1 Gasket 1.50 29
2 Water Level Guage 12.99 30
3 Faucet Repair Kit 4.89 8
4 Teflon Thread Seal Tape (50 ft roll) 3.30 12
5 shutoff valve 6.50 10
6 Cable 5.00 18
7 Extension Cord (14/3, 25 ft) 27.95 11
8 Light switch (15 amp) 2.79 10
9 Ceiling Fan (52 inch) 79.95 0
10 Vinyl Electrical Tape (20 ft roll) 0.79 30
11 GFI Tester 9.35 5
12 Pump 39.00 20
13 Gasket 1.50 29
14 Water Level Guage 12.99 30
15 Faucet Repair Kit 4.89 8
16 Teflon Thread Seal Tape (50 ft roll) 3.30 12
17 shutoff valve 6.50 10
18 Cable 5.00 18
19 Extension Cord (14/3, 25 ft) 27.95 11
20 Light switch (15 amp) 2.79 10
21 Ceiling Fan (52 inch) 79.95 0
22 Vinyl Electrical Tape (20 ft roll) 0.79 30
23 GFI Tester 9.35 5
24 records.
Command: n
Enter description for new Item: Broom
Enter unit cost for new Item: 9.99
Enter initial quantity for the new Item: 12
Announcing a new inventory Item: Broom
We now have 25 different inventory Items in stock!
Command: pItem Num Description Cost Quantity
-------- ----------- ---- --------
0 Pump 39.00 20
1 Gasket 1.50 29
2 Water Level Guage 12.99 30
3 Faucet Repair Kit 4.89 8
4 Teflon Thread Seal Tape (50 ft roll) 3.30 12
5 shutoff valve 6.50 10
6 Cable 5.00 18
7 Extension Cord (14/3, 25 ft) 27.95 11
8 Light switch (15 amp) 2.79 10
9 Ceiling Fan (52 inch) 79.95 0
10 Vinyl Electrical Tape (20 ft roll) 0.79 30
11 GFI Tester 9.35 5
12 Pump 39.00 20
13 Gasket 1.50 29
14 Water Level Guage 12.99 30
15 Faucet Repair Kit 4.89 8
16 Teflon Thread Seal Tape (50 ft roll) 3.30 12
17 shutoff valve 6.50 10
18 Cable 5.00 18
19 Extension Cord (14/3, 25 ft) 27.95 11
20 Light switch (15 amp) 2.79 10
21 Ceiling Fan (52 inch) 79.95 0
22 Vinyl Electrical Tape (20 ft roll) 0.79 30
23 GFI Tester 9.35 5
24 Broom 9.99 12
25 records.
Command: n
Enter description for new Item: Dust Pan
Enter unit cost for new Item: 5.99
Enter initial quantity for the new Item: 5
Announcing a new inventory Item: Dust Pan
We now have 26 different inventory Items in stock!
Command: pItem Num Description Cost Quantity
-------- ----------- ---- --------
0 Pump 39.00 20
1 Gasket 1.50 29
2 Water Level Guage 12.99 30
3 Faucet Repair Kit 4.89 8
4 Teflon Thread Seal Tape (50 ft roll) 3.30 12
5 shutoff valve 6.50 10
6 Cable 5.00 18
7 Extension Cord (14/3, 25 ft) 27.95 11
8 Light switch (15 amp) 2.79 10
9 Ceiling Fan (52 inch) 79.95 0
10 Vinyl Electrical Tape (20 ft roll) 0.79 30
11 GFI Tester 9.35 5
12 Pump 39.00 20
13 Gasket 1.50 29
14 Water Level Guage 12.99 30
15 Faucet Repair Kit 4.89 8
16 Teflon Thread Seal Tape (50 ft roll) 3.30 12
17 shutoff valve 6.50 10
18 Cable 5.00 18
19 Extension Cord (14/3, 25 ft) 27.95 11
20 Light switch (15 amp) 2.79 10
21 Ceiling Fan (52 inch) 79.95 0
22 Vinyl Electrical Tape (20 ft roll) 0.79 30
23 GFI Tester 9.35 5
24 Broom 9.99 12
25 Dust Pan 5.99 5
26 records.
Command: o
Enter name of output file: testData02.txt
26 records written to file.
Command: n
Enter description for new Item: Gasoline Can
Enter unit cost for new Item: 8.99
Enter initial quantity for the new Item: 34
ERROR: initial quantity must be >= zero and <= 30.
Enter initial quantity for the new Item: 29
Announcing a new inventory Item: Gasoline Can
We now have 27 different inventory Items in stock!
Command: pItem Num Description Cost Quantity
-------- ----------- ---- --------
0 Pump 39.00 20
1 Gasket 1.50 29
2 Water Level Guage 12.99 30
3 Faucet Repair Kit 4.89 8
4 Teflon Thread Seal Tape (50 ft roll) 3.30 12
5 shutoff valve 6.50 10
6 Cable 5.00 18
7 Extension Cord (14/3, 25 ft) 27.95 11
8 Light switch (15 amp) 2.79 10
9 Ceiling Fan (52 inch) 79.95 0
10 Vinyl Electrical Tape (20 ft roll) 0.79 30
11 GFI Tester 9.35 5
12 Pump 39.00 20
13 Gasket 1.50 29
14 Water Level Guage 12.99 30
15 Faucet Repair Kit 4.89 8
16 Teflon Thread Seal Tape (50 ft roll) 3.30 12
17 shutoff valve 6.50 10
18 Cable 5.00 18
19 Extension Cord (14/3, 25 ft) 27.95 11
20 Light switch (15 amp) 2.79 10
21 Ceiling Fan (52 inch) 79.95 0
22 Vinyl Electrical Tape (20 ft roll) 0.79 30
23 GFI Tester 9.35 5
24 Broom 9.99 12
25 Dust Pan 5.99 5
26 Gasoline Can 8.99 29
27 records.
Command: i
Enter name of input file: fasteners.txt
7 records loaded to array.
Command: i
Enter name of input file: miscellaneous.txt
4 records loaded to array.
Command: pItem Num Description Cost Quantity
-------- ----------- ---- --------
0 Pump 39.00 20
1 Gasket 1.50 29
2 Water Level Guage 12.99 30
3 Faucet Repair Kit 4.89 8
4 Teflon Thread Seal Tape (50 ft roll) 3.30 12
5 shutoff valve 6.50 10
6 Cable 5.00 18
7 Extension Cord (14/3, 25 ft) 27.95 11
8 Light switch (15 amp) 2.79 10
9 Ceiling Fan (52 inch) 79.95 0
10 Vinyl Electrical Tape (20 ft roll) 0.79 30
11 GFI Tester 9.35 5
12 Pump 39.00 20
13 Gasket 1.50 29
14 Water Level Guage 12.99 30
15 Faucet Repair Kit 4.89 8
16 Teflon Thread Seal Tape (50 ft roll) 3.30 12
17 shutoff valve 6.50 10
18 Cable 5.00 18
19 Extension Cord (14/3, 25 ft) 27.95 11
20 Light switch (15 amp) 2.79 10
21 Ceiling Fan (52 inch) 79.95 0
22 Vinyl Electrical Tape (20 ft roll) 0.79 30
23 GFI Tester 9.35 5
24 Broom 9.99 12
25 Dust Pan 5.99 5
26 Gasoline Can 8.99 29
27 Turnbuckle 3.80 25
28 Siding nails (box of 100) 4.00 20
29 Flat washer (box of 100) 2.80 30
30 Machine screw (box of 100) 3.20 10
31 Hex bolt (box of 100) 6.50 23
32 Hex nut (box of 100) 3.80 15
33 Sheet Metal Screw (qty 100) 1.50 28
34 Door Hinges (3-pack) 6.30 10
35 Rubber work boots (1 pair) 28.00 5
36 Leather Work Gloves (1 pair) 12.00 8
37 Long Handle Grass Shear 30.00 5
38 records.
Command: o
Enter name of output file: testData03.txt
38 records written to file.
Command: q
Exit.
InventoryItem.h
// This class has overloaded constructors.
#ifndef INVENTORYITEM_H
#define INVENTORYITEM_H
#include < string >
using namespace std;
class InventoryItem
{
private:
string description; // The item description
double cost; // The item cost
int units; // Number of units on hand
public:
// Constructor #1
InventoryItem()
{ // Initialize description, cost, and units.
description = "";
cost = 0.0;
units = 0; }
// Constructor #2
InventoryItem(string desc)
{ // Assign the value to description.
description = desc;
// Initialize cost and units.
cost = 0.0;
units = 0; }
// Constructor #3
InventoryItem(string desc, double c, int u)
{ // Assign values to description, cost, and units.
description = desc;
cost = c;
units = u; }
// Mutator functions
void setDescription(string d)
{ description = d; }
void setCost(double c)
{ cost = c; }
void setUnits(int u)
{ units = u; }
// Accessor functions
string getDescription() const
{ return description; }
double getCost() const
{ return cost; }
int getUnits() const
{ return units; }
};
#endif