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
|
#include <iostream>
#include <string>
using namespace std;
void getNames(string[], int);
void getScores(string[], double [], int);
double getAverage(double[], int);
void displayTotal(string[], char[], double[]);
int main()
{
const int NAMES = 5;
const int GRADES = 5;
const int SCORES = 4;
string studentNames[NAMES];
char grades[GRADES] = { 'A', 'B', 'C', 'D', 'F' };
double studentTest1[SCORES];
double studentTest2[SCORES];
double studentTest3[SCORES];
double studentTest4[SCORES];
double studentTest5[SCORES];
double average[GRADES];
// GET NAMES OF THE 5 STUDENTS
getNames(studentNames, NAMES);
cout << endl;
//GET THE 4 SCORES FROM STUDENT 1
getScores(studentNames, studentTest1, SCORES);
cout << endl;
//GET THE 4 SCORES FROM STUDENT 2
getScores(studentNames, studentTest2, SCORES);
cout << endl;
//GET THE 4 SCORES FROM STUDENT 3
getScores(studentNames, studentTest3, SCORES);
cout << endl;
//GET THE 4 SCORES FROM STUDENT 4
getScores(studentNames, studentTest4, SCORES);
cout << endl;
//GET THE 4 SCORES FROM STUDENT 5
getScores(studentNames, studentTest5, SCORES);
cout << endl;
//GET AVERAGE OF STUDENT 1 TEST SCORE
average[0] = getAverage(studentTest1, SCORES);
displayTotal(studentNames, grades, average);
//GET AVERAGE OF STUDENT 2 TEST SCORE
average[1] = getAverage(studentTest2, SCORES);
displayTotal(studentNames, grades, average);
//GET AVERAGE OF STUDENT 3 TEST SCORE
average[2] = getAverage(studentTest3, SCORES);
displayTotal(studentNames, grades, average);
//GET AVERAGE OF STUDENT 4 TEST SCORE
average[3] = getAverage(studentTest4, SCORES);
displayTotal(studentNames, grades, average);
//GET AVERAGE OF STUDENT 5 TEST SCORE
average[4] = getAverage(studentTest5, SCORES);
displayTotal(studentNames, grades, average);
system("pause");
return 0;
}
void getNames(string name[], int numNames)
{
for (int count = 0; count < numNames; count++)
{
cout << "Name of Student " << (count + 1) << ": ";
cin >> name[count];
}
}
void getScores(string studentNames[], double studentTest[], int test)
{
static int studentNum = 0; // STATIC INT TO KEEP NAME UNTIL FUNCTION CHANGES TO REUSE
cout << "\tOnly scores 0 - 100 will be accepted." << endl;
for (int count = 0; count < test; count++)
{
do {
cout << "Score of Test " << (count + 1) << " From Student " << studentNames[studentNum] << ": ";
cin >> studentTest[count];
} while (studentTest[count] < 0 || studentTest[count] > 100);
}
studentNum++;
}
double getAverage(double studentTest[], int num)
{
int sum = 0;
for (int count = 0; count < num; count++)
{
sum += studentTest[count];
}
sum = (sum / 4);
return sum;
}
void displayTotal(string studentNames[], char grade[], double avg[])
{
static int count = 0;
if (avg[count] < 60)
{
cout << studentNames[count] << " scored " << avg << " and got an " << grade[4] << endl;
count++;
}
else if (avg[count] <= 69)
{
cout << studentNames[count] << " scored " << avg << " and got a " << grade[3] << endl;
count++;
}
else if (avg[count] <= 79)
{
cout << studentNames[count] << " scored " << avg << " and got a " << grade[2] << endl;
count++;
}
else if (avg[count] <= 89)
{
cout << studentNames[count] << " scored " << avg << " and got a " << grade[1] << endl;
count++;
}
else
{
cout << studentNames[count] << " scored " << avg << " and got an " << grade[0] << endl;
count++;
}
}
|