1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include <fstream>
#include <string>
#include<iomanip>
using namespace std;
void readSales(ifstream &dataSales);
void CalcProfits(ifstream &dataSales, string &Item, double &Cost ,double &SalePrice, double &Profit, double &TotalProfit, double &SalesNumber)
;
void display(ifstream &dataSales, ofstream &outdataSales,string &Item, double &Cost ,double &SalePrice, double &Profit, double &TotalProfit, double &SalesNumber);
int main()
{
ifstream dataSales;
ofstream outdataSales;
string Item;
double Cost, SalePrice, Profit, TotalProfit, SalesNumber;
readSales(dataSales);
CalcProfits(dataSales, Item, Cost , SalePrice, Profit, TotalProfit, SalesNumber);
display(dataSales, outdataSales, Item, Cost , SalePrice, Profit, TotalProfit, SalesNumber);
return 0;
}
void readSales(ifstream &dataSales)
{
dataSales.open("sales.txt");
}
void CalcProfits(ifstream &dataSales, string &Item, double &Cost ,double &SalePrice, double &Profit, double &TotalProfit, double &SalesNumber)
{
TotalProfit=0;
while (dataSales >> Item >> Cost >> SalePrice >> SalesNumber)
{
Profit=(SalePrice-Cost)*SalesNumber;
TotalProfit+=Profit;
}
}
void display(ifstream &dataSales,ofstream &outdataSales, string &Item, double &Cost ,double &SalePrice, double &Profit, double &TotalProfit, double &SalesNumber)
{
cout <<"REPORT SALES PC SHOP SDN BHD"<<endl;
cout <<"__________________________________________"<<endl;
cout <<" ITEM"<<setw(35)<<"PROFIT"<<endl;
cout <<"__________________________________________"<<endl;
while (outdataSales << Item << Cost << SalePrice << SalesNumber)
{
cout << Item << setw(20) << Profit;
}
cout <<"__________________________________________"<<endl;
cout << "TOTAL PROFIT" <<setw(25) << TotalProfit<<endl;
}
| |