I need C++ Code for this problem A teacher has 20 students who have taken 4 test
ID: 3711073 • Letter: I
Question
I need C++ Code for this problem
A teacher has 20 students who have taken 4 tests. The teacher uses the following grading system to assign a letter grade to a student, based on the average of his or her four test scored:
Test Score Letter Grade
90 – 100 A
80 - 89 B
70 – 79 C
60 – 69 D
0 – 59 F
Write a program class that uses a String array object to hold the 20 students’ names, an array containing 20 groups of four doubles to hold each students’ set of test scores. The program class should have methods that return a specific students’ name, the average test score and a letter grade based on the array.
Demonstrate the class in a program that allows the user to enter each student’s name and his or her four test scores. It should then display each student’s average test score and letter grade. In addition create an average score over the entire class for each test and an average over all for all tests for all students and display these values
Input can be typed in via the keyboard or entered through a data file containing the information on the next page.
Input validation: Do not accept test scores less than zero or greater than 100.
Explanation / Answer
#include<iostream>
#include<string>
using namespace std;
class Marks
{
public:
string names[20];
double marks[20][4];
string getName(int i)
{
return names[i];
}
double getAvg(int i)
{
double avg = 0;
for(int j = 1 ; j <= 4 ; j++)
{
avg = avg + marks[i][j];
}
avg = avg / 4;
return avg;
}
char getGrade(int i)
{
double avg = getAvg(i);
if(avg >= 90)
return 'A';
else if(avg >= 80)
return 'B';
else if(avg >= 70)
return 'C';
else if(avg >= 60)
return 'D';
else if(avg >= 0)
return 'F';
}
double getTestAvg(int j)
{
double avg = 0;
for(int i = 0 ; i < 20 ; i++)
{
avg = avg + marks[i][j];
}
avg = avg / 20;
return avg;
}
};
int main()
{
Marks m;
double t;
int n = 20;
for(int i = 0 ; i < n; i++)
{
cout<<"Enter Name: ";
cin>>m.names[i];
cout<<"Enter Marks: ";
for(int j = 1 ; j <= 4 ; j++)
{
cin>>t;
while(t<0 || t>100)
{
cout<<"Re-enter marks of test #"<<j<<": ";
cin>>t;
}
m.marks[i][j] = t;
}
}
double clsAvg = 0;
for(int i = 0; i < n ; i++)
{
clsAvg = clsAvg + m.getAvg(i);
cout<<m.getName(i)<<" "<<m.getAvg(i)<<" "<<m.getGrade(i)<<endl;
}
clsAvg = clsAvg / n;
cout<<"Class Average is: "<<clsAvg<<endl;
for(int i = 1 ; i <= 4 ; i++)
{
cout<<"Average in test #"<<i<<": "<<m.getTestAvg(i)<<endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.