Question: Write a C++ program with a function to read in the file parts.txt into a vector of structs. The data file is on ANGEL in

Write a C++ program with a function to read in the file parts.txt into a vector of structs.

The data file is on ANGEL in zipped format. The first few lines of the file look like:

P-13725 A 23 61.46

P-13726 B 12 51.08

P-13754 D 27 4.56

P-13947 C 34 27.71

Representing part number, Class, On hand balance, cost. After the vector of structs has been filled, display a menu which allows the user to request the following reports:

Total cost of inventory.

A count of parts of each class.

Cost of inventory for a class.

Part with the highest cost of inventory.

Part with lowest cost of inventory.

Exit.

Each of these should be a function. Ive posted a typical run on the next page.

Hints:

Use system(cls); to clear the screen after the user makes a choice. These are the prototypes of the functions I used:

bool readFile(vector <Parts> &pVector);

int displayMenu();

double totalCost(const vector <Parts> &pVector);

void countByClass(const vector <Parts> & pVector, vector <int> &classCounts);

double costForClass(char classIn, const vector <Parts> & pVector);

string highestCost(const vector <Parts> &pVector);

string lowestCost(const vector <Parts> &pVector);

void displayCounts(const vector & classCounts);

Here is the code for countByClass:

void countByClass(const vector <Parts> & pVector, vector <int> &classCounts)

{

for (int i = 0; i < classCounts.size(); i++)

classCounts[i] = 0;

for (int i = 0; i<pVector.size(); i++)

{

classCounts[pVector[i].cls - 65]++; // 'A' = 65 'B' = 66

}

}

So, if pVector[0].cls contains an A, which is ASCII 65, we subtract 65 from it which makes it 0, and we add one to classCounts[0]. If it were a B, ASCII 66, 66-65 = 1, so we add one to classCounts[1], etc.

R E P O R T S M E N U

1. Total cost of inventory.

2. A count of parts of each class.

3. Cost of inventory for a class.

4. Part with the highest cost of inventory.

5. Part with lowest cost of inventory.

6. Exit.

1

Your choice was 1

Total cost of inventory is $343136.99

R E P O R T S M E N U

1. Total cost of inventory.

2. A count of parts of each class.

3. Cost of inventory for a class.

4. Part with the highest cost of inventory.

5. Part with lowest cost of inventory.

6. Exit.

Your choice was 2

Count of parts by class

A 85

B 70

C 76

D 61

E 7

F 6

R E P O R T S M E N U

1. Total cost of inventory.

2. A count of parts of each class.

3. Cost of inventory for a class.

4. Part with the highest cost of inventory.

5. Part with lowest cost of inventory.

6. Exit.

Your choice was 3

Which class?

A

Cost of inventory for class A is $191519.80

Your choice was 4

The part with the highest cost of inventory is P-27850

Your choice was 5

The part with the lowest cost of inventory is P-30538

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!