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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void readData(int list[], int size);
int main()
{
int size = 50;
int scores[50] = {0};
int range (0);
int rangeA(0);
int rangeB(0);
int rangeC(0);
int rangeD(0);
int a;
int b;
double avg;
int c;
int d;
double avgA;
int e;
int f;
double avgB;
int g;
int h;
double avgC;
int i;
int j;
double avgD;
int aAvg (0);
int aAvgA(0);
int aAvgB(0);
int aAvgC(0);
int aAvgD(0);
int paa, paaA, paaB, paaC, paaD;
readData(scores, size); // call the function to load the array
sort(scores, scores + 50);
for ( int n=0 ; n<50 ; ++n )
{
if(scores[n] <=599&&scores[n] >= 300)
{
rangeA = rangeA + 1;
c = scores[n];
d = scores[n] + c;
}
if(scores[n] <=699&&scores[n] >= 600)
{
rangeB = rangeB + 1;
e = scores[n];
f = scores[n] + e;
}
if(scores[n] <=799&&scores[n] >= 700)
{
rangeC = rangeC + 1;
g = scores[n];
h = scores[n] + g;
}
if(scores[n] <=850&&scores[n] >= 800)
{
rangeD = rangeD + 1;
i = scores[n];
j = scores[n] + i;
}
range = range + 1;
a = scores[n];
b = scores[n] + a;
}
int highA, highB, highC, highD;
int lowA, lowB, lowC, lowD;
avg = b/range;
avgA = d/rangeA;
avgB = f/rangeA;
avgC = h/rangeA;
avgD = j/rangeA;
lowA = scores[1];
highA = scores[rangeA];
lowB = scores[rangeA + 1];
highB = scores[rangeB];
lowC = scores[rangeB +1];
highC = scores[rangeC];
lowD = scores[rangeC + 1];
highD = scores[rangeD];
for ( int n=0 ; n<50 ; ++n )
{
if(scores[n] > avg)
{
aAvg = aAvg + 1;
}
if(scores[n] > avgA && scores[n] <= 599)
{
aAvgA = aAvgA + 1;
}
if(scores[n] > avgB && scores[n] <= 699)
{
aAvgB = aAvgB + 1;
}
if(scores[n] > avgC && scores[n] <= 799)
{
aAvgC = aAvgC + 1;
}
if(scores[n] > avgD && scores[n] <= 850)
{
aAvgD = aAvgD + 1;
}
}
paa = (aAvg/range)*100;
paaA = (aAvgA/rangeA)*100;
paaB = (aAvgB/rangeB)*100;
paaC = (aAvgC/rangeC)*100;
paaD = (aAvgD/rangeD)*100;
cout << "Score Range No. Average Lowest Highest No. of scores above average Percent above average" << endl;
cout << "300-599 " << rangeA << " " << avgA << " " << lowA << " " << highA << " " << aAvgA << " " << paaA << "%" << endl;
cout << "600-699 " << rangeB << " " << avgB << " " << lowB << " " << highB << " " << aAvgB << " " << paaB << "%" << endl;
cout << "700-799 " << rangeC << " " << avgC << " " << lowC << " " << highC << " " << aAvgC << " " << paaC << "%" << endl;
cout << "800-850 " << rangeD << " " << avgD << " " << lowD << " " << highD << " " << aAvgD << " " << paaD << "%" << endl;
cout << "Average: " << avg << endl;
cout << "No. of scores above average: " << aAvg << endl;
cout << "Percent above average: " << paa << "%" << endl;
system("PAUSE");
return 0;
}
void readData(int list[], int size) // This function loads an array from an input file
{
ifstream infile;
infile.open("Input.DAT");
if (!infile)
{
cout << "Cannot open the input file. Program terminates!"
<< endl;
return ;
}
int score;
int index = 0;
infile >> list[index];
while (index < size - 1)
{
index = index + 1;
infile >> list[index];
}
infile.close();
}
|