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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include<iostream>
#include<fstream>
#include <string>
#include <sstream>
#include<vector>
using namespace std;
void writeFile();
void readFile(ifstream &inputFile);
int main()
{
writeFile();
ifstream inputFile;
inputFile.open("QuarterlySalesDataFile.txt");
if (!inputFile)
{
cout << "Unable to open file";
}
else
{
readFile(inputFile);//arguments
inputFile.close();
}
return 0;
}
void writeFile()
{
ofstream outputFile;
string filename;
cout<<"Enter your filename to save";
cin>>filename;
cout<<"File created!";
outputFile.close();
}
void readFile(ifstream &inputFile)//parameters
{
int iD, targetId=0, i=0;
int monthI, month[12]={}, amntTotal=0;
float amountofSale, amnt=0, accountTotal=0;
float commissionRate=0.26;
float commission, comRate;
string months[12]{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
bool firstiD=true;
while (inputFile>> iD>>monthI>>amountofSale)
{
accountTotal+=amountofSale;
commission=commissionRate*amnt;
if(firstiD)
{
targetId=iD;
firstiD = false;
}
if (targetId==iD)
{
cout <<endl<< iD << ' ' << months[monthI-1] << ' ' << amountofSale<<endl;
amnt+=amountofSale;
}
else
{
cout<<amnt<<endl;
comRate=commissionRate*accountTotal;
cout<<commission<<endl;
amnt=0;
commission=0;
amnt+=amountofSale;
cout << iD << ' ' << months[monthI-1] << ' ' << amountofSale<<endl;
targetId=iD;
firstiD=true;
}
}
cout<<amnt<<endl;
comRate=commissionRate*amnt;
cout<<comRate<<endl;
cout<<endl<<accountTotal<<endl;
comRate=commissionRate*accountTotal;
cout<<comRate;
}
| |