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 162 163 164
|
void getNames (string[], int);
void getScores (string[], double[], double[], double[], double[], double[], const int, const int);
void getLowest (double[], double[], double[], double[], double[], double[], const int);
void getAvg (string[], double[], double[], double[], double[], double[], double[], const int);
void getGrade (string[], double[], char[], const int);
int main()
{
const int NAMES = 5; // Number of names to hold.
const int GRADES = 5; // Number of grades to hold.
const int SCORES = 4; // Number of scores to hold for each student.
string name[NAMES]; // Five string array for names.
char grade[GRADES]; // Five char array for grades.
// Four double array to hold student scores.
double stu1[SCORES], stu2[SCORES], stu3[SCORES], stu4[SCORES], stu5[SCORES];
double avg[GRADES]; // To hold average.
double sum = 0; // To hold sum.
// Get five student names from user.
getNames(name, NAMES);
getScores(name, stu1, stu2, stu3, stu4, stu5, SCORES, NAMES);
getLowest(stu1, stu2, stu3, stu4, stu5, avg, SCORES);
getAvg(name, stu1, stu2, stu3, stu4, stu5, avg, SCORES);
getGrade(name, avg, grade, GRADES);
// Make sure we place the end message on a new line
cout << endl;
// The following is system dependent. It will only work on Windows
system("PAUSE");
/*
// A non-system dependent method is below
cout << "Press any key to continue";
cin.get();
*/
return 0;
}
void getNames(string name[], int totNames)
{
for (int count = 0; count < totNames; count++)
{
cout << "Enter the name of student " << (count + 1) << ": ";
cin >> name[count];
}
}
void getScores(string names[], double s1[], double s2[], double s3[], double s4[], double s5[], const int scores, const int totNames)
{
for (int j = 0; j < scores; j++)
{
cout << "Enter score " << (j+1) << " for " << names[0] << endl;
cin >> s1[j];
while (s1[j] < 0 || s1[j] > 100)
{
cout << "ERROR: Scores must be 1-100 only: ";
cin >>s1[j];
}
}
for (int j = 0; j < scores; j++)
{
cout << "Enter score " << (j+1) << " for " << names[1] << endl;
cin >> s2[j];
while (s2[j] < 0 || s2[j] > 100)
{
cout << "ERROR: Scores must be 1-100 only: ";
cin >>s2[j];
}
}
for (int j = 0; j < scores; j++)
{
cout << "Enter score " << (j+1) << " for " << names[2] << endl;
cin >> s3[j];
while (s3[j] < 0 || s3[j] > 100)
{
cout << "ERROR: Scores must be 1-100 only: ";
cin >>s3[j];
}
}
for (int j = 0; j < scores; j++)
{
cout << "Enter score " << (j+1) << " for " << names[3] << endl;
cin >> s4[j];
while (s4[j] < 0 || s4[j] > 100)
{
cout << "ERROR: Scores must be 1-100 only: ";
cin >>s4[j];
}
}
for (int j = 0; j < scores; j++)
{
cout << "Enter score " << (j+1) << " for " << names[4] << endl;
cin >> s5[j];
while (s5[j] < 0 || s5[j] > 100)
{
cout << "ERROR: Scores must be 1-100 only: ";
cin >>s5[j];
}
}
}
void getAvg (string names[], double s1[], double s2[], double s3[], double s4[], double s5[],double avge[], const int scores)
{
double sum = 0;
for(int k = 0; k < scores; k++)
sum+=s1[k];
avge[0] = sum/scores;
cout << "The grade average for " << names[0] << " is: " << avge[0] << endl;
sum = 0;
for(int k = 0; k < scores; k++)
sum+=s2[k];
avge[1] = sum/scores;
cout << "The grade average for " << names[1] << " is: " << avge[1] << endl;
sum = 0;
for(int k = 0; k < scores; k++)
sum+=s3[k];
avge[2] = sum/scores;
cout << "The grade average for " << names[2] << " is: " << avge[2] << endl;
sum = 0;
for(int k = 0; k < scores; k++)
sum+=s4[k];
avge[3] = sum/scores;
cout << "The grade average for " << names[3] << " is: " << avge[3] << endl;
sum = 0;
for(int k = 0; k < scores; k++)
sum+=s5[k];
avge[4] = sum/scores;
cout << "The grade average for " << names[4] << " is: " << avge[4] << endl;
}
void getLowest(double s1[], double s2[], double s3[], double s4[], double s5[], double avg[], const int scores)
{
double lowest;
lowest = s1[0];
for (int i = 1; i < scores; i++)
{
if (s1[i] < lowest)
lowest = s1[i];
}
}
void getGrade (string names[], double aver [], char grade[], const int grades)
{
for (int m = 0; m < grades; m++)
{
if (aver[m] < 60)
grade[m] = 'F';
else if (aver[m] < 70)
grade[m] = 'D';
else if (aver[m] < 80)
grade[m] = 'C';
else if (aver[m] < 90)
grade[m] = 'B';
else
grade[m] = 'A';
}
for(int n = 0; n < grades; n++)
{
cout << "Letter grade average for " << names[n] << " is: " << grade[n] << endl;
}
}
|