Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will input letters grade(A,B,C,D,F), the number of which is

ID: 3551976 • Letter: W

Question

Write a program that will input letters grade(A,B,C,D,F), the number of which is input by the user (a maximum of 50 grades). The grades will be read into array. A function will be called five times(once for each letter grade) and will return the total number of grades in that category. The function must be passed 3 parameters: the array, the number of elements in the array, and the letter to be searched for and counted (A, B, C, D or F). The program will print the number of each grade.

Additional Information:

Store all the input grades one by one in an array;

The function prototype looks like the following:

int countChar(char[], int, char);

The function will go through the array and count how many occurrences for the designated letter grade.

Sample Run:

Please input the number of grades to be read in.(1-50): 6

all grades must be upper case A B C D or F

?Input a grade: A

Input a grade: C

Input a grade: A

Input a grade: B

Input a grade: B

Input a grade: D

Number of As = 2

Number of Bs =2

Number of Cs = 1

Number of Ds = 1

Number of Fs = 0

???

??

Explanation / Answer

#include <iostream>
using namespace std;
int countChar(char[], int, char);
int main(){int i,n;
char grade[50],letters[5]={'A','B','C','D','F'};
cout<<"Please input the number of grades to be read in.(1-50): ";
cin>>n;
cout<<"all grades must be upper case A B C D or F ";
for(i=0;i<n;i++)
{cout<<"Input a grade: ";
cin>>grade[i];
}
for(i=0;i<5;i++)
   cout<<"Number of "<<letters[i]<<"s ="<<countChar(grade,n,letters[i])<<endl;
system("pause");
return 0;
}
int countChar(char g[], int n, char l)
{int i,sum=0;
for(i=0;i<n;i++)
   if(g[i]==l)
       sum++;
return sum;
}   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote