Grade Book Modification- C++ Modify the grade book application so that it drops
ID: 3907754 • Letter: G
Question
Grade Book Modification- C++
Modify the grade book application so that it drops each students lowest score when determing the test scre averages and letter grades.
grade book application:
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
char letterGrade(double score);
int main()
{
char names[5][25]; //student names
char grades[5]; //letter grades
double scores[5][4]; //test scores
double avgScore[5]; //average of 4 test scores
for(int i=0;i<5;i++)
{
cout<<" Enter student "<<(i+1)<<" name: ";
cin>>names[i];
cout<<"Enter his 4 scores: ";
for(int j=0;j<4;j++)
{
cin>>scores[i][j];
while(scores[i][j] > 100 || scores[i][j] <0)
{
cout<<" test score should between 0 and 100"<<endl;
cout<<"enter test score: ";
cin>>scores[i][j];
}
}
}
//finding average score of each student
//and letter grade
for(int i=0;i<5;i++)
{
avgScore[i] = 0;
for(int j=0;j<4;j++)
avgScore[i] += scores[i][j];
avgScore[i] /= 4;
grades[i] = letterGrade(avgScore[i]);
}
//displaying average test score and letter grade
cout<<" Student Name Average Score Letter Grade"<<endl;
for(int i=0;i<5;i++)
{
cout.setf(ios::fixed,ios::floatfield);
cout.precision(2);
cout<<names[i]<<" "<<setprecision(2)<<avgScore[i]<<" "<<grades[i]<<endl;
}
return 0;
}
//return letter grade based on the test score
//passed as parameter
char letterGrade(double score)
{
if(score >= 90 && score <=100)
return 'A';
else if(score >= 80 && score <90)
return 'B';
else if(score >= 70 && score <80)
return 'C';
else if(score >= 60 && score <70)
return 'D';
else
return 'F';
}
Explanation / Answer
Pkease find the modified code below with comments:
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
char letterGrade(double score);
int main()
{
char names[5][25]; //student names
char grades[5]; //letter grades
double scores[5][4]; //test scores
double avgScore[5]; //average of 4 test scores
for(int i=0;i<5;i++)
{
cout<<" Enter student "<<(i+1)<<" name: ";
cin>>names[i];
cout<<"Enter his 4 scores: ";
for(int j=0;j<4;j++)
{
cin>>scores[i][j];
while(scores[i][j] > 100 || scores[i][j] <0)
{
cout<<" test score should between 0 and 100"<<endl;
cout<<"enter test score: ";
cin>>scores[i][j];
}
}
}
//finding average score of each student
//and letter grade
for(int i=0;i<5;i++)
{
avgScore[i] = 0;
int min=scores[i][0];//storing first value in the row as minimum
for(int j=0;j<4;j++)
{
if(min>scores[i][j])//comparing min with other values in row to find minimum score
min=scores[i][j];
avgScore[i] += scores[i][j];
}
avgScore[i]-=min;//dropping minscore frm sum
avgScore[i] /= 3;//calculating the average
grades[i] = letterGrade(avgScore[i]);
}
//displaying average test score and letter grade
cout<<" Student Name Average Score Letter Grade"<<endl;
for(int i=0;i<5;i++)
{
cout.setf(ios::fixed,ios::floatfield);
cout.precision(2);
cout<<names[i]<<" "<<setprecision(2)<<avgScore[i]<<" "<<grades[i]<<endl;
}
return 0;
}
//return letter grade based on the test score
//passed as parameter
char letterGrade(double score)
{
if(score >= 90 && score <=100)
return 'A';
else if(score >= 80 && score <90)
return 'B';
else if(score >= 70 && score <80)
return 'C';
else if(score >= 60 && score <70)
return 'D';
else
return 'F';
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.