this is the first project that my questions based off of: #include<iostream> usi
ID: 3625690 • Letter: T
Question
this is the first project that my questions based off of:#include<iostream>
using namespace std;
struct record
{
double quiz_1;
double quiz_2;
double midyear, midyear_one;
double final, final_average;
double quiz_average;
char final_grade;
double total_grade;
};
void input(record& the_grades);
void output(record& the_grades);
int main()
{
record grades;
input(grades);
output(grades);
return 0;
}
void input(record& the_grades)
{
cout <<"To get your final output grade input all your scores ";
cout << "Enter quiz_1 grade out of 10 points: ";
cin >> the_grades.quiz_1;
cout << "Enter quiz_2 grade out of 10 points: ";
cin >> the_grades.quiz_2;
cout << "Enter midyear Exam grade out of 100 points: ";
cin >> the_grades.midyear;
cout << "Enter Final Exam grade out of 100 points: ";
cin >> the_grades.final;
}
void output(record& the_grades)
{
the_grades.quiz_average = (((the_grades.quiz_1/10) + (the_grades.quiz_2/10))/2) * .25;
the_grades.final_average = (the_grades.final/100) * .5;
the_grades.midyear_one = (the_grades.midyear/100) *.25;
the_grades.total_grade = the_grades.quiz_average + the_grades.final_average + the_grades.midyear_one;
cout << endl << endl;
cout <<"quiz_1: "<< the_grades.quiz_1 <<"/10";
cout << endl;
cout <<"quiz_2: "<< the_grades.quiz_2 <<"/10";
cout << endl;
cout <<"Midyear exam: " << the_grades.midyear<<"/100";
cout << endl;
cout <<"Final exam: " << the_grades.final<<"/100";
cout << endl;
cout <<"Final grade: "<< "%" << the_grades.total_grade*100;
cout << endl;
cout <<"Letter grade: ";
if(the_grades.total_grade*100 < 60)
{
cout << "F";
}
if((the_grades.total_grade*100 > 60)&&(the_grades.total_grade*100 < 70))
{
cout << "D";
}
if((the_grades.total_grade*100 > 70)&&(the_grades.total_grade*100 < 80))
{
cout << "C";
}
if((the_grades.total_grade*100 > 80)&&(the_grades.total_grade*100 < 90))
{
cout << "B";
}
if(the_grades.total_grade*100 > 90)
{
cout << "A";
}
cout << endl;
}
redo programming project 1 (or do it for the first time), but this time make the student record type a class type rather than a structure type. the student record class should have member variables for all the input data described in programing project 1 and a member variable for the student's weighted average numeric score for the entire course as well as a member variable for the students final letter grade. make all member variables private. include member functions for each of the following: member functions to set each of the member variables to values given as an argument(s) to the function, member functions to retrieve the data from each of the member variables , a void function that calculates the student's weighted average numeric score for the entire course and sets the corresponding member variable, and a void function that calculates the students final letter grade and sets the corresponding member variable.
Explanation / Answer
#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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.