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
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#define SIZE 28
using namespace std;
int ArrayFromFile (int A[], int Q[])
{
int C = 0;
ifstream inFile;
inFile.open("grades.txt");
while(C<Q &&!inFile.eof())
{
inFile >> A[C];
C+=1;
}
inFile.close();
if (C!=Q) cout << "Quanity of data file doesn't match array size";
return C;
}
void sortArray (int A[], int Q)
{
int P, PASS, T;
for (PASS=1; PASS<Q; PASS++)
for (P=0;P<=-1-PASS;P++)
if (A[P]>A[P+1]) { T=A[P]; A[P]=A[P+1]; A[P+1]=T;}
}
void stats ( int A[], int Q[], int &MIN, int &MAX, float &AVG)
{
int TOTAL=0;
int I;
int COUNT=0;
int T;
MIN = 100;
MAX = 0;
for (I=0; I<Q; I++)
{
if (A[T]>=Q && A[T]<=100)
{
COUNT+=1;
TOTAL+=A[I];
if (A[I]<MIN) MIN=A[I];
if (A[I]<MAX) MAX=A[I];
}
}
AVG=static_cast<float>(TOTAL/COUNT);
}
void displayCatergory (int A[], int Q[], int &MIN, int &MAX, float &AVG)
{
int I;
int QI=0, QU=0, QS=0, QO=0;
cout << "Student\n\n";
cout << "Score | Category\n";
cout << "-------+----------\n";
for (I=0; I<Q[SIZE]; I++)
{
cout << setw(8) << A[I] << " | ";
if (A[I]<0 || A[I]>100) {QI++; cout << "Invalid";}
else if (A[I]<60) { QU++; cout << "Unstatisfactory";}
else if (A[I]<90) { QU++; cout << "statisfactory";}
else {QO++; cout << "Outstanding";}
cout << endl;
}
cout << "\nStatistics:\n\n";
cout << setw(8) << Q << " | Scores Read From File" << endl;
cout << setw(8) << QO << " | Outstanding Scores (90-100)" << endl;
cout << setw(8) << QS << " | Statisfactory Scores (60-89)" << endl;
cout << setw(8) << QU << " | Unstatisfactory Scores (0-59)" << endl;
cout << setw(8) << QI << " | Invalid Scores (Under 0 or Over 100)" << endl;
cout << setw(8) << setprecision(2) << fixed << AVG << " | Average Score" << endl;
cout << setw(8) << MAX << " | Highest Score" << endl;
cout << setw(8) << MIN << " | Lowest Score" << endl;
}
int main (void)
{
cout << "Student\n";
cout << "4/14/15\ class example\n";
cout << "Test Score Summary\n";
int SCORES;
int QTY[SIZE];
int MIN, MAX;
float AVG;
QTY = ArrayFromFile(SCORES, QTY);
sortArray(SCORES, QTY);
stats(SCORES, QTY, MIN, MAX, AVG);
displayCatergory(SCORES, QTY, MIN, MAX, AVG);
return 0;
}
|