A teacher has five students who have taken four tests. The teacher uses the foll
ID: 3737060 • Letter: A
Question
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:
90-100 A
80-89 B
70-79 C
60-69 D
0-59 F
Instructions (very important):
Using C++ language, 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 five arrays 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 great than 100.
Please, do not use global variables except as constants and use a few thoughtful functions to simplify the program. You will need to pass by reference and by array to end up not using global variables (except for constants)
Explanation / Answer
#include<iostream>
#include<string>
using namespace std;
int main()
{
const int size=5;
//array for students’ names for fixing size
string sNames[size];
//for loop for geting Names of students
for(int i=0;i<5;i++)
{
cout<<“please Enter a student’s name: “;
cin>>sNames[i]; //to take input from users
}
//to get scores
double scoreForS[size][4], avg[size],sum[size]={0,0,0,0,0};
for(int x=0;x<5;x++)
{
for(int y=0;y<4;y++)
{
cout<<“Enter the score for student “<<(x+1)<<” “;
cin>>scoreForS[x][y];
//input validation
while(scoreForS[x][y]<0||scoreForS[x][y]>100)
{
cout<<“Error.The range of score is 0 to 100. Reenter : “;
cin>>scoreForS[x][y];
}
sum[x]+=scoreForS[x][y];
}
}
//drop lowest score
double lowest[size];
for(int a=0;a<5;a++)
{
lowest[a]= scoreForS[a][0];
for(int b=1;b<4;b++)
{
if (lowest[a]>scoreForS[a][b])
lowest[a]= scoreForS[a][b];
}
sum[a]-=lowest[a];
}
//get avg
for(int c=0;c<5;c++)
{
avg[c]=sum[c]/3.0;
}
//scale
char grade[size];
for(int d=0;d<5;d++)
{
if(avg[d]>=90)grade[d]=’A’;
else if(avg[d]>=80 && avg[d]<=89)grade[d]=’B’;
else if(avg[d]>=70 && avg[d]<=79)grade[d]=’C’;
else if(avg[d]>=60 && avg[d]<=69) grade[d]=’D’;
else grade[d]=’F’;
cout<<“ Student “<<sNames[d]<<” get “<<grade[d];
}
system(“pause”);
return 0;
}
it will be helpful .i hope you like this ANS
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.