This code must be written in C++ Write a program to calculate grades. Follow the
ID: 3724356 • Letter: T
Question
This code must be written in C++
Write a program to calculate grades. Follow the grading system which is attached above (For 0 = F, thats the only variable we need to worry about, the FIN,WF, and WU need to be omitted). User provides number of courses taken in a semester. Then for each course provides individual percentages. Program has to calculate the grade letter from percentage for each course. Then display the cumilative GPA of that particular semester. Write a function called letterGradeCalculator. Pass appropriate parameters to the function. Function should return the letter grade for a single course.
The grade point average is computed on a scale in which 4.00 4.00 3.70 3.30 300 2.70 2.30 - 2.00 -170 130 100 -0.70 F. FIN, WF, and WU0.00 A- B+ 8 B- C- D- D-Explanation / Answer
#include <iostream>
using namespace std;
double avg(double arr[],int n)
{
double s=0;
for(int i=0;i<n;i++)
s+=arr[i];
s=s/n;
return s;
}
int count(char s[],int c)
{
if(s[c]=='')
return c;
else
return count(s,++c);
}
char letterGradeCalculator(double score)
{
char grade;
if(score>=4.00)
grade='A+';
else if(score>=3.70)
grade='A-';
else if(score>=3.30)
grade='B+';
else if(score>=3.00)
grade='B';
else if(score>=2.70)
grade='B-';
else if(score>=2.30)
grade='C+';
else if(score>=2.00)
grade='C';
else if(score>=1.70)
grade='C-';
else if(score>=1.30)
grade='D+';
else if(score>=1.00)
grade='D';
else if(score>=0.70)
grade='D-';
else
grade='F';
return grade;
}
int main() {
int n;
char gradesArray[10];//for 10 students
cout<<"Enter the number of grades: ";
cin>>n;
double scores[10][n];
for(int i=0;i<10;i++)
{
cout<<"Enter the scores for student "<<i+1<<" ";
for(int j=0;j<n;j++)
cin>>scores[i][j];
double av=avg(scores[i],n);
gradesArray[i]=letterGradeCalculator((av/n)*0.4);
}
cout<<"The grades are ";
for(int i=0;i<10;i++)
cout<<"Student "<<i+1<<" "<<gradesArray[i]<<" ";
return 0;
}