Write a program that reads a file called parts.dat to create an inventory report
ID: 647167 • Letter: W
Question
Write a program that reads a file called parts.dat to create an inventory report based on the data in the file. The display should consist of the part number, current balance, and amount that is necessary to bring the inventory to the minimum level. The parts.dat file contains the following data:
Sample output:
Enter an input file name: parts.dat
Part Current Amt
Number Balance Needed
----------------------------------------------
AP123 47 28
CB876 61 39
PC389 38 12
ZN264 21 129
The file has been successfully written.
Explanation / Answer
#include<iostream>
#include<fstream>
#include<string.h>
#include<iomanip>
using namespace std;
int main(){
char fileName[20];
cout << "Enter an input file name : ";
cin >> fileName;
ifstream in;
in.open(fileName);
char partNumber[10];
int total,used,minimum;
int currentBalance,amountNeeded;
cout << " Part Current Amt ";
cout << " Number Balance Needed ";
cout << "--------------------------------------------- ";
while(!in.eof()){
in >> partNumber;
in >> total;
in >> used;
in >> minimum;
currentBalance = total - used;
amountNeeded = minimum - currentBalance;
cout << " " << partNumber << " " << currentBalance << " " << amountNeeded << " ";
}
cout << " The file has been successfully written ";
return 0;
}