Write a program to read the parts.txt file and display the cost of inventory for
ID: 3903832 • Letter: W
Question
Write a program to read the parts.txt file and display the cost of inventory for each of the part classes. The file contains parts of class A, B, C and D. An example of a typical line in this file would be: P-11191 A 10 34.29 This is part number P-11191, a class A part, of which there are 10 in stock and each costs $34.29. Your program, therefore, would increment the Count of class A parts by one and add $342.90 (10 $34.29) to the class A inventory. Note that the count is only incremented by 1, not by 10 this tracks the number of unique different types of class A parts, not the total in-stock quantity of each respective part. The parts file is on Canvas in this week's module in .zip format. After downloading it, right click and choose Extract. SCWindowslsystem32cmd.exe INUENTORY REPORT A parts Count: B parts Count: C parts Count: D parts Count Unknown Count: Press any key to continue - 85 Ualue of inventory 191180.0? 69 Ualue of inventory74764.16 77 Ualue of inventory 50322.30 60 Ualue of inventory 22416.49 13 Ualue of inventory: 4282.68Explanation / Answer
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream file("input.txt");
int countA = 0, countB = 0, countC = 0, countD = 0, unknown = 0;
double valueA = 0, valueB = 0, valueC = 0, valueD = 0, unknownValue = 0;
string part;
char type;
int stock;
double cost;
while(file >> part >> type >> stock >> cost) {
if(type == 'A') {
countA ++;
valueA += stock * cost;
} else if(type == 'B') {
countB ++;
valueB += stock * cost;
} else if(type == 'C') {
countC ++;
valueC += stock * cost;
} else if(type == 'D') {
countD ++;
valueD += stock * cost;
} else {
unknown ++;
unknownValue += stock * cost;
}
}
cout << "----------------------------INVENTORY REPORT----------------------------" << endl;
cout << "A parts Count: " << countA << " Value of Inventory: " << valueA << endl;
cout << "B parts Count: " << countB << " Value of Inventory: " << valueB << endl;
cout << "C parts Count: " << countC << " Value of Inventory: " << valueC << endl;
cout << "D parts Count: " << countD << " Value of Inventory: " << valueD << endl;
cout << "Unknown parts Count: " << unknown << " Value of Inventory: " << unknownValue << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.