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
|
#include <fstream> // stream for input files
#include <iomanip>
#include <iostream> // stream for output files
using namespace std;
void printgraph(ofstream& outFile, int a); //function of issue
void printout(ofstream& outFile, int a[8]);
int main()
{
int score;
int scorerange[8] = {0,0,0,0,0,0,0,0};
int scoreacc[8] = {0,0,0,0,0,0,0,0};
int avg[8] = {0,0,0,0,0,0,0,0};
int i;
int list[27];
ifstream inFile; //input file stream variable
ofstream outFile; //output file stream variable
inFile.open("scoresin.txt"); //WORKS
if (!inFile) //WORKS
{
cout << "Cannot open the input file!" << endl;
return 0;
}
outFile.open ("scoresout.out"); //WORKS
cout << "Group Score" << endl; //WORKS
cout << " # 0 20 40 60 80 100 120 140 160 180 200" << endl; //WORKS
for (i = 0; i < 26; i++) //WORKS
{
inFile >> list[i];
score = list[i];
if (0 < score && score < 25)
scorerange[0]++, scoreacc[0] += score; // FILL IN FOR REST
else if (24 < score && score< 50)
scorerange[1]++, scoreacc[1] += score;
else if (49 < score && score< 75)
scorerange[2]++, scoreacc[2] += score;
else if (74 < score && score< 100)
scorerange[3]++, scoreacc[3] += score;
else if (99 < score && score< 125)
scorerange[4]++, scoreacc[4] += score;
else if (124 < score && score< 150)
scorerange[5]++, scoreacc[5] += score;
else if (149 < score && score< 175)
scorerange[6]++, scoreacc[6] += score;
else if (174 < score && score< 201)
scorerange[7]++, scoreacc[7] += score;
}
printout(outFile, scorerange); //WORKS
for (i = 0; i++; i < 8)
{
avg[i] = scoreacc[i]/scorerange[i];
}
printgraph(outFile, avg[0]);
printgraph(outFile, avg[1]);
printgraph(outFile, avg[2]);
printgraph(outFile, avg[3]);
inFile.close(); //WORKS
outFile.close(); //WORKS
return 0;
}
void printgraph(ofstream& outFile, int a) // sub in for book
{
int count;
for (count = 1; count < a; count++)
outFile<< '*' ;
outFile<< endl;
}
void printout(ofstream& outFile, int a[8]) //WORKS
{
outFile << "Students with scores betwen 0 - 24 are: " << a[0] << endl;
outFile << "Students with scores betwen 25 - 49 are: " << a[1] << endl;
outFile << "Students with scores betwen 50 - 74 are: " << a[2] << endl;
outFile << "Students with scores betwen 75 - 99 are: " << a[3] << endl;
outFile << "Students with scores betwen 100 - 124 are: " << a[4] << endl;
outFile << "Students with scores betwen 125 - 149 are: " << a[5] << endl;
outFile << "Students with scores betwen 150 - 174 are: " << a[6] << endl;
outFile << "Students with scores betwen 175 - 200 are: " << a[7] << endl;
}
|