You gave me this code for my gradebook, but I need you to modify the gradebook s
ID: 3628640 • Letter: Y
Question
You gave me this code for my gradebook, but I need you to modify the gradebook so it drops each student's lowest score when determining the test averages and letter grades. I feel some of my karma points should come back cause i asked for this the first time. It runs fine just my modification need to take place. thanks.
Here is the code:
//Header files section
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//function prototype
char letterGrade(double score);
//main function
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
//inputting student name and test
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];
//validating test score
while(scores[i][j] > 100 || scores[i][j] <0)
{
cout<<" test score should be in
between 0- 100"<<endl;
cout<<"enter test score: ";
cin>>scores[i][j];
}
}
}
//finding average score of each student
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;
//function call to calculate grade
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;
}
system("pause");
}
//grade value passed as parameter and returns
character grade
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
please rate - thanks
some advice-don't rate until you check it, and wait for my answer-I try to be complete-hope you don't mind I'm fixing the code too.
message me if any problems
//Header files section
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//function prototype
char letterGrade(double score);
double lowestScore(double[][4],int);
//main function
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
//inputting student name and test
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++)
{cout<<"Enter score "<<j+1<<": ";
cin>>scores[i][j];
//validating test score
while(scores[i][j] > 100 || scores[i][j] <0)
{
cout<<" test score should be in between 0- 100"<<endl;
cout<<"Enter score "<<i+1<<": ";
cin>>scores[i][j];
}
}
}
//finding average score of each student
for(int i=0;i<5;i++)
{
avgScore[i] = 0;
for(int j=0;j<4;j++)
avgScore[i] += scores[i][j];
avgScore[i]-=lowestScore(scores,i);
avgScore[i] /=3;
//function call to calculate grade
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;
}
system("pause");
}
//find lowest score to subtract
double lowestScore(double scores[][4],int i)
{int j;
double low;
low=scores[i][0];
for(j=1;j<4;j++)
if(scores[i][j]<low)
low=scores[i][j];
return low;
}
//grade value passed as parameter and returns character grade
char letterGrade(double score)
{
if(score >= 90)
return 'A';
else if(score >= 80)
return 'B';
else if(score >= 70)
return 'C';
else if(score >= 60)
return 'D';
else
return 'F';
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.