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
|
#include <iostream>
#include <string>
using namespace std;
int numberofstudents();
void initialize(int&, int&, int&, int&, int&);
int getnumbergrade(); // <--
void classifygrades (int&, int&, int&, int&, int&, int&);
void printresults (int, int, int, int, int);
int main(){
int gradeCountA, gradeCountB, gradeCountC, gradeCountD, gradeCountF;
initialize(gradeCountA, gradeCountB, gradeCountC, gradeCountD, gradeCountF);
int students = numberofstudents();
int grade = 0;
for (int i = 0; i < students; ++i)
{
grade = getnumbergrade();
classifygrades(grade, gradeCountA, gradeCountB, gradeCountC,
gradeCountD, gradeCountF);
}
printresults (gradeCountA, gradeCountB, gradeCountC,
gradeCountD, gradeCountF);
return 0;
}
int numberofstudents(){
int students;
cout << "Enter number of students: ";
cin >> students;
return students;
}
void initialize(int& gradeCountA, int& gradeCountB, int& gradeCountC,
int& gradeCountD, int& gradeCountF)
{
gradeCountA = 0;
gradeCountB = 0;
gradeCountC = 0;
gradeCountD = 0;
gradeCountF = 0;
}
int getnumbergrade()
{
int aGrade = 0;
cout << "Enter a student's grade: ";
cin >> aGrade;
if (aGrade < 0 || aGrade > 100){
cout << "Invalid grade. Please re-enter: ";
}
return aGrade;
}
void classifygrades (int& grade, int& gradeCountA, int& gradeCountB,
int& gradeCountC, int& gradeCountD, int& gradeCountF)
{
if ((grade >= 90) && (grade <= 100))
gradeCountA++;
else if ((grade >= 80) && (grade <= 89))
gradeCountB++;
else if ((grade >=70) && (grade <= 79))
gradeCountC++;
else if ((grade >= 60) && (grade <= 69))
gradeCountD++;
else
gradeCountF++;
}
void printresults(int gradeCountA, int gradeCountB, int gradeCountC,
int gradeCountD, int gradeCountF)
{
cout << "Total students received A: " << gradeCountA << endl;
cout << "Total students received B: " << gradeCountB << endl;
cout << "Total students received C: " << gradeCountC << endl;
cout << "Total students received D: " << gradeCountD << endl;
cout << "Total students received F: " << gradeCountF << endl;
}
|