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
|
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
// constant for how many grades are to be entered
const int ARRAY_SIZE = 50;
// a function called GetData to read and store data into two arrays,
void GetData(int scores[], int i);
// character value for the grade
char alphaGrade(double avg);
// a function called Average that is used to calculate the average test score and grade,
void Average(int scores[], char grade[],double avg[]);
// function called PrintResults to output the results.
void PrintResults(double avg[],int scores[],char grade[],int i, int j);
int static i;
int j;
int main()
{
int scores[ARRAY_SIZE];
char grade[ARRAY_SIZE];
double avg[ARRAY_SIZE];
do {
GetData(scores, i);
Average(scores, grade, avg);
PrintResults(avg, scores, grade, i, j);
}
while (scores >= 0);
}
void GetData(int scores[], int i){
for (int i = 0 ; i < 50 ; i ++){
cout << "Enter 50 grades: " << endl;
cin >> scores[i];
}
}
char alphaGrade(double avg)
{
if(avg>=90 && avg<=100)
return 'A';
else if(avg>=80 && avg<=89)
return 'B';
if(avg>=70 && avg<=79)
return 'C';
if(avg>=60 && avg<=69)
return 'D';
if(avg>=50 && avg<=59)
return 'F';
}
void Average(int scores[], char grade[], double avg[], int i, int j)
{
double sum =0;
for(int j=0; j<5; j++){
sum+= scores[i];
avg[i] = sum/static_cast<double> (5);
grade[i] = alphaGrade(avg[i]);
}
}
void PrintResults(double avg[],int scores[],char grade[], int i)
{
for (i = 0; i < ARRAY_SIZE; i++){
cout << setw(8) << "Average" << avg << endl;
cout << setw(4) << "Grade" << grade << endl;
}
}
|