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
|
#include <iostream>
using namespace std;
//Function prototype
int GradeCount(char [], int, char);
int main ()
{
const int SIZE = 50; //Array size
int numOfGrades; //Variable to hold num of grades the user is entering
char grades[numOfGrades]; //Array to hold grades
char A,B,C,D,E,F; //Character for call to function
char letter; //Letter
cout << "LETTER GRADES\n" <<endl;
//How many grades are you entering??
cout << "How many grades do you want to enter: ";
cin >> numOfGrades;
cout << "\nPlease enter grade score in uppercase letters only!\n" <<endl;
//Loop to populate the grades array!
for(int index = 0; index < numOfGrades; index++)
{
cout << "Grade #" << ( index+1) << ": ";
cin >> grades[index];
}
GradeCount(grades, SIZE, A);
GradeCount(grades, SIZE, B);
GradeCount(grades, SIZE, C);
GradeCount(grades, SIZE, D);
GradeCount(grades, SIZE, E);
GradeCount(grades, SIZE, F);
}
//********************************************
//Definition of function gradeCount. *
//This function accepts an arry of chars the *
//array size and a char as it's arguments. *
//the contents of the array ar displayed! *
//********************************************
int gradeCount (char grades[], int numOfGrades, char letter)
{
for(int index = 0; index < numOfGrades; index++)
{
int amtOfValue = 0; //Tally number of each grade value
if (grades[index] == letter)
amtOfValue = amtOfValue + 1;
return amtOfValue;
}
}
|