Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

1.

Program Description
This program is written to read the inventory part file. It will ask user to input the name of an inventory file. User will also have to input the ID number, quantity on hand and the price for each unit. In the end, the program will read through the inventory file and displays only those part records for which the total value of that part exceeds $3000.00.

2. Flow Chart
Start

Read file

An inventory file was created

Read num

Read id[i], quantity[i] and price[i]

Store id[i], quantity[i] and price[i]

i =0

Yes

Is i<num?

Is total[i]>3000?
i ++

No

Yes
Print id[i], quantity[i],price [i] and total[i]

End

3. Source Code
#include <fstream> #include <iostream> #include <iomanip> #include<string> using namespace std; const int size=100; int main() { //declaring the variables double price[size], total[size]={0}; int id[size],quantity[size],num; string file; //read the file name cout<<"Enter the name of the inventory file: "; cin >> file; cout << endl; //capture number of time user want to record cout<<"How many time do you want to record? :"; cin>>num; //create a file ofstream SaveFile (file.c_str()); //read user input data for(int i=0;i<num;i++) { cout<<"Enter ID No: "; cin>>id[i]; cout<<"Enter quantity: "; cin>>quantity[i]; cout<<"Price ($): "; cin>>price[i]; cout<<endl; //save data into created file SaveFile<<id[i]<<"\t"<<quantity[i]<<"\t"<<price[i]<<endl; SaveFile<<endl; } SaveFile.close(); //open a file to read ifstream infile(file.c_str()); cout<<left<<setw(10)<<"ID No."<<setw(12)<<"Quantity"<<setw(10)<<"Price"<<setw(15)<<"TOTAL"<<endl; //read stored file and calculate the data int i=0; while(!infile.eof()) { infile>>id[i]>>quantity[i]>>price[i]; total[i]=quantity[i]*price[i]; i++;

} //display calculated results for(int i=0; i<num ;i++) { if(total[i]>3000) cout<<fixed<<left<<setw(10)<<id[i]<<setw(12)<<quantity[i]<<setw(10)<< setprecision(2)<<price[i]<<setw(15)<<showpoint<<setprecision(2)<<total[i]<<endl; } infile.close();

return 0; }

4. Output

You might also like