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 108 109 110 111 112 113 114 115 116 117 118 119
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void displayHeader();
void readIntoSales(ifstream &fp, float Numsales, float sales[], float SIZE);
float computeAverage(ifstream &fp, float sales[], float SIZE, float Numsales);
int compareAboveArrays(float &Numsales,float sales[], float targetNumber[],bool meet[], float SIZE, float salesAverage, int sum);
float performanceInfo(float compareInfoBelow, float SIZE, float NumberOfFalses);
void displayResults(float totalAverage, float comparingInfoAbove, float infoPerformance);
int main()
{
int NumberOfFalses = 0;
float Numsales, salesInfo, totalAverage, results, comparingInfoAbove, infoPerformance, salesAverage;
const int SIZE = 12;
float targetNumber[] = {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 sales[SIZE];
bool meet[SIZE];
displayHeader();
ifstream fp;
fp.open("sales.dat");
if(!fp)
{
cout <<"Error opening the file!" <<endl;
}
while(fp.eof()==false)
{
readIntoSales(fp, Numsales, sales, SIZE);
totalAverage = computeAverage(fp, sales, SIZE, Numsales);
comparingInfoAbove = (Numsales, targetNumber, sales, meet, SIZE, salesAverage, NumberOfFalses);
infoPerformance = performanceInfo(comparingInfoAbove, SIZE, NumberOfFalses);
displayResults(totalAverage, comparingInfoAbove, infoPerformance);
}
return 0;
}
void displayHeader()
{
cout<< "Store Statistics"<<endl;
cout<<" "<<endl;
cout<<" Dept " << " Average " << " Above " << " Below " << " Performance " <<endl;
cout<<"----------------------------------------------------------------" <<endl;
}
void readIntoSales(ifstream &fp, float Numsales, float sales[], float SIZE)
{
fp >>Numsales;
for (int i = 0; i < SIZE; i++)
sales[i] = Numsales;
}
float computeAverage(ifstream &fp, float sales[], float SIZE, float Numsales)
{
float sum = 0, salesAverage;
for(int i = 0; i < SIZE; i++)
{
fp>>Numsales;
sum += Numsales;
}
salesAverage = sum/SIZE;
return salesAverage;
}
int compareAboveArrays(float &Numsales,float sales[], float targetNumber[], bool meet[], float SIZE, float &salesAverage, int NumOfFalses)
{
int NumberOfFalses = 0;
for (int i = 0; i < SIZE; i++)
{
if(sales[i] < targetNumber[i])
meet[i] = false;
else
meet[i] = true;
}
for(int j = 0; j < SIZE; j++)
if(meet[j] = false)
NumberOfFalses++;
else
12 - NumberOfFalses;
return NumberOfFalses;
}
float performanceInfo(float compareAboveArrays,float meet[], float SIZE, float &NumberOfFalses)
{
string perform;
for (int i = 0; i < SIZE; i++)
if(NumberOfFalses < 4 )
perform = "satisfactory";
else
perform = "unsatisfactory";
return perform;
}
float performanceInfo(float compareAboveArrays,float meet[], float SIZE, float &NumberOfFalses)
{
string perform;
for (int i = 0; i < SIZE; i++)
if(NumberOfFalses < 4 )
perform = "satisfactory";
else
perform = "unsatisfactory";
return perform;
}
void displayResults(float totalAverage, float comparingInfoAbove,float infoPerformance)
{
cout<<totalAverage << " " <<comparingInfoAbove <<infoPerformance <<endl;
}
|