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

Please write in C++ A teacher has five students who have taken four tests. The t

ID: 3828131 • Letter: P

Question

Please write in C++

A teacher has five students who have taken four tests. The teacher uses the following grading scale to assign a letter grade to a student, based on the average of his or her four test scores. Notice that the grade scales are written in interval notation. Write a program that uses an array of string objects to hold the five student names, an array of five characters to hold the five students' letter grades, and another array of four doubles to hold each student's set of test scores. The program should allow the user to enter each student's name and his or her four test scores. It should then calculate and display each student's average test score and a letter grade based on the average. Input Validation: Do not accept test scores less than 0 or greater than 100.

Explanation / Answer

#include <iostream>

using namespace std;

int main()
{
string names[5];
char grades[5];
double average[5];
int scores;
int totalScores = 0;
for(int i=0; i<5; i++){
cout<<"Enter the student name: "<<(i+1)<<": ";
cin >> names[i];
cout<<"Enter the four scores: "<<endl;
for(int j=0;j<4; j++){
cin >> scores;
if(scores <0 || scores > 100){
cout<<"Invalid score. "<<endl;
j--;
}
totalScores = totalScores+ scores;
}
average[i] = totalScores/(double)4;
if (average[i] >= 90){
grades[i]='A';
}
else if (average[i] >= 80 && average[i] <90){
grades[i]='B';
}
else if (average[i] >= 70 && average[i] <80){
grades[i]='C';
}
else if (average[i] >= 60 && average[i] <70){
grades[i]='D';
}
else{
grades[i]='F';
}
}
cout<<"Student details: "<<endl;
for(int i=0; i<5; i++){
cout<<"Name: "<<names[i]<<" Average: "<<average[i]<<" Grade: "<<grades[i]<<endl;
}
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                             

Enter the student name: 1: Suresh                                                                                                                                                                                                                                        

Enter the four scores:                                                                                                                                                                                                                                                   

11 22 33 44                                                                                                                                                                                                                                                              

Enter the student name: 2: Anshu                                                                                                                                                                                                                                         

Enter the four scores:                                                                                                                                                                                                                                                   

44 55 66 77                                                                                                                                                                                                                                                              

Enter the student name: 3: Sekhar                                                                                                                                                                                                                                        

Enter the four scores:                                                                                                                                                                                                                                                   

77 88 99 100                                                                                                                                                                                                                                                             

Enter the student name: 4: Revathi                                                                                                                                                                                                                                       

Enter the four scores:                                                                                                                                                                                                                                                   

55 66 77 88                                                                                                                                                                                                                                                              

Enter the student name: 5: Murapaka                                                                                                                                                                                                                                      

Enter the four scores:                                                                                                                                                                                                                                                   

44 77 68 101                                                                                                                                                                                                                                                             

Invalid score.                                                                                                                                                                                                                                                           

99                                                                                                                                                                                                                                                                       

Student details:                                                                                                                                                                                                                                                         

Name: Suresh Average: 27.5 Grade: F                                                                                                                                                                                                                                      

Name: Anshu Average: 88 Grade: B                                                                                                                                                                                                                                         

Name: Sekhar Average: 179 Grade: A                                                                                                                                                                                                                                       

Name: Revathi Average: 250.5 Grade: A                                                                                                                                                                                                                                    

Name: Murapaka Average: 347.75 Grade: A