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 103 104 105 106 107
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void displayHeader();
float readSales(ifstream &fp, float &sales);
float computeAverage(ifstream &fp, float &sales, float avg);
int numberAboveAverage(int &above, int &numbAbove, float &salesAmount[12], float standardSales[12]);
int numbweBelowAverage(int &below, int &numbBelow, float &salesAmount[12], float standardSales[12]);
string performanceOfDept(string &below);
int main()
{
float salesAmount[12];
float standardSales[] = {23.0, 33.1, 21.0, 23.5, 54.0, 34.3, 35.0, 45.0, 56.3, 45.6, 34.0, 55.0};
float compareArrays[12];
float sales, deptAvg, above, below, performance, avg;
int numbAbove, numbBelow;
displayHeader();
ifstream fp;
fp.open("sales.dat");
if(!fp)
cout<<"Error opening the file!" <<endl;
while(!fp.eof())
{
salesAmount = readSales(&fp, sales);
deptAvg = computeAverage(&fp, &sales, avg);
above = numberAboveAverage(&above, &numbAbove);
below = numbersBelowAverage(&below, &numbBelow)
performance = performanceOfDept(&below);
}
return 0;
}
void displayHeader()
{
cout<< "Store Statistics"<<endl;
cout<<" "<<endl;
cout<<"Dept" << "Average" << "Above" << "Below" << "Performance" <<endl;
cout<<"----------------------------------------------------------------" <<endl;
}
void readSales(ifstream &fp, float &sales)
{
fp >> sales;
for(int i = 0; i < sales; i++)
{
salesAmount[i] = sales;
}
}
flaot computeAverage(ifstream &fp, float &sales, float avg)
{
float total = 0;
total += sales;
avg = total/12;
}
int numbersAboveAverage(int &above, int &numbAbove, float &salesAmount[], float &standardSales[])
{
if(salesAmount[i] > standardSales[i])
{
for(above = 0; above <= 7; above++)
{
numbAbove += above;
}
}
}
int numbersBelowAverage(int &below, int &numbBelow, float &salesAmount[], float &standardSales[])
{
if(salesAmount[i] < standardSales[i])
{
for(int below = 0; below <= 7; below--)
{
numbBelow += below;
}
}
}
string performanceOfDept(int &below)
{
if(below > 4)
cout<<"unsatisfied"<<endl;
else
cout<<"Satisfied"<<endl;
}
void displayResults(ifstream &fp, float sales, int above, int below, string performance, float deptAvg, float sale\
sAmount)
{
cout<<"1" <<deptAvg <<above <<below <<performance <<endl;
cout<<"2" <<deptAvg <<above <<below <<performance <<endl;
cout<<"3" <<deptAvg <<above <<below <<performance <<endl;
cout<<"4" <<deptAvg <<above <<below <<performance <<endl;
cout<<"5" <<deptAvg <<above <<below <<performance <<endl;
cout<<"6" <<deptAvg <<above <<below <<performance <<endl;
cout<<"7" <<deptAvg <<above <<below <<performance <<endl;
}
|