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
|
#include <iostream>
#include <cctype>
using namespace std;
int function1( char arr[], int numberofgrades,char grades[], int whichgrade)
{
int tally = 0;
//for loop
for(int i =0; i<numberofgrades; i++)
{
//if arr[i] == some grade
switch (whichgrade)
{
case 1 : if(arr[i] == grades[0])
{
tally++;
}
break;
case 2 : if(arr[i] == grades[1])
{
tally++;
}
break;
case 3 : if(arr[i] == grades[2])
{
tally++;
}
break;
case 4 : if(arr[i] == grades[3])
{
tally++;
}
break;
case 5 : if(arr[i] == grades[4])
{
tally++;
}
break;
}
}
return tally;
}
//
int main ()
{
//step 1 ask the user for a number of grades less than or equal to 50
int numberofgrades =0;
char grades[50];
char inputtedgrade;
char possiblegrades[] = {'A', 'B', 'C', 'D', 'F'};
bool tester;
//verify the inputted grades
do{
cout << "Enter the number of grades you have to enter (less than or equal to 50)" ;
cin >> numberofgrades;
}while (numberofgrades <1 || numberofgrades >50);
for(int k =0; k<numberofgrades; k++)
{
tester = (grades[k] == 'A') || (grades[k] == 'B') ||(grades[k] == 'C') || (grades[k] == 'D')||(grades[k] == 'F');
do{
cout << "Enter grade number " << k+1 << endl;
cin >> inputtedgrade;
grades[k] = toupper(inputtedgrade);
tester = (grades[k] == 'A') || (grades[k] == 'B') ||(grades[k] == 'C') || (grades[k] == 'D')||(grades[k] == 'F');
}while(!tester);
}
//char grades[]= {'E', 'B', 'B', 'A' ,'C', 'C', 'C', 'C','C' ,'C' ,'D', 'D','F', 'F','F','A'};
//A = 3
//B = 2
//C = 6
//D = 2
//F = 3
int talleyed[6];
for(int j = 1; j<6; j++)
{
talleyed[j] = function1(grades,16, possiblegrades, j);
}
cout << "The number of As is " << talleyed[1] << endl;
cout << "The number of Bs is " << talleyed[2] << endl;
cout << "The number of Cs is " << talleyed[3] << endl;
cout << "The number of Ds is " << talleyed[4] << endl;
cout << "The number of Fs is " << talleyed[5] << endl;
system("pause");
return 0;
}
|