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

It works, however, the final grade is never displayed #include <iostream> using

ID: 3644780 • Letter: I

Question

It works, however, the final grade is never displayed


#include <iostream>
using namespace std;
const int CLASS_SIZE = 5;
class StudentRecord
{
private: int studentNumber;
double quiz1;
double quiz2;
double midterm;
double final;
double average;
char grade;
public:
void input(StudentRecord& student);
void computeGrade(StudentRecord& student);
void output(const StudentRecord student);
};
int main()
{
StudentRecord student[CLASS_SIZE];
for(int i = 0; i < CLASS_SIZE; i++)
student[i].input(student[i]);
for(int i = 0; i < CLASS_SIZE; i++)
{
student[i].computeGrade(student[i]);
student[i].output(student[i]);
cout << endl;
}
system("pause");
}
void StudentRecord:: input(StudentRecord &student)
{
cout << "Enter student number: ";
cin >> student.studentNumber;
cout << " Enter two 10 point quizes" << endl;
cin >> student.quiz1 >> student.quiz2;
cout << " Enter the midterm and final exam grades." << "These are 100 point tests ";
cin >> student.midterm >> student.final;
}
void StudentRecord:: computeGrade(StudentRecord& student)
{
double quizAvg= (student.quiz1 + student.quiz2)/2.0;
double quizAvgNormalized = quizAvg * 10;
student.average = student.final * 0.5 +
student.midterm * 0.25 +quizAvgNormalized * 0.25;
char letterGrade[]= "FFFFFFDCBAA";
int index = static_cast<int>(student.average/10);
if(index < 0 || 10 <= index)
{
cout << "Bad numeric grade: "
<< student.average << endl
<< " Aborting. ";
abort();
}
student.grade = letterGrade[index];
}
void StudentRecord:: output(const StudentRecord student)
{
cout << "The record for student number: " << student.studentNumber << endl;
cout<< "The quiz of grades are: " << student.quiz1 << " " << student.quiz2 << endl;
cout<< "The midterm and exam grades are: " << student.midterm << " " << student.final << endl;
cout<< "The numeric average is: " << student.average << endl;
cout<< "Grade assigned is "<< student.grade<< endl;
}



Explanation / Answer

please rate - thanks

your problem is this instruction

if(index < 0 || 10 <= index)

it should read

if(index < 0 || index>10)

#include <iostream>
using namespace std;
const int CLASS_SIZE = 2;
class StudentRecord
{
private: int studentNumber;
double quiz1;
double quiz2;
double midterm;
double final;
double average;
char grade;
public:
void input(StudentRecord& student);
void computeGrade(StudentRecord& student);
void output(const StudentRecord student);
};
int main()
{
StudentRecord student[CLASS_SIZE];
for(int i = 0; i < CLASS_SIZE; i++)
student[i].input(student[i]);
for(int i = 0; i < CLASS_SIZE; i++)
{
student[i].computeGrade(student[i]);
student[i].output(student[i]);
cout << endl;
}
system("pause");
}
void StudentRecord:: input(StudentRecord &student)
{
cout << "Enter student number: ";
cin >> student.studentNumber;
cout << " Enter two 10 point quizes" << endl;
cin >> student.quiz1 >> student.quiz2;
cout << " Enter the midterm and final exam grades." << "These are 100 point tests ";
cin >> student.midterm >> student.final;
}
void StudentRecord:: computeGrade(StudentRecord& student)
{
double quizAvg= (student.quiz1 + student.quiz2)/2.0;
double quizAvgNormalized = quizAvg * 10;
student.average = student.final * 0.5 +
student.midterm * 0.25 +quizAvgNormalized * 0.25;
char letterGrade[]= "FFFFFFDCBAA";
int index = static_cast<int>(student.average/10);
if(index < 0 || index>10 )
{
cout << "Bad numeric grade: "
<< student.average << endl
<< " Aborting. ";
abort();
}
student.grade = letterGrade[index];
}
void StudentRecord:: output(const StudentRecord student)
{
cout << "The record for student number: " << student.studentNumber << endl;
cout<< "The quiz of grades are: " << student.quiz1 << " " << student.quiz2 << endl;
cout<< "The midterm and exam grades are: " << student.midterm << " " << student.final << endl;
cout<< "The numeric average is: " << student.average << endl;
cout<< "Grade assigned is "<< student.grade<< endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote