1. redo this program but this time make the student record type a class type rat
ID: 3652473 • Letter: 1
Question
1.redo this program 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.
#include<iostream>
using namespace std;
struct record //contains values that are recorded
{
double quiz1;
double quiz2;
double midyear, midyear_one;
double final, final_one;
double quiz_average;
char final_grade;
double total_grade;
};
void instructions();
//post condition: Displays instructions
void input(record& the_grades);
//pre condition: gets the grades for quiz 1,quiz 2, midyear exam and final
//post condition: sets the variables in structure
void output(record& the_grades);
// pre-condition: calculates the final grade and gets the letter grade
// post condition: outputs the grades to the user
int main()
{
char run_again; // variable to allow user to run program again
record grades;
instructions();// outputs instructions
do
{
input(grades); // gets grades
output(grades);// outputs the values
cout << endl << endl;
cout << "Run again?:";// asks user if the user wants to run again
cout << "(enter Y or N)";
cout << endl;
cin >> run_again;// if y then the program will run again
}while((run_again == 'y')||(run_again == 'Y'));
cout << "<program end>";
cout << endl << endl;
system("pause");
return 0;
}
void instructions()
{
cout << "Welcome to the program student record";
cout << endl << "this program takes in 2quizes, a final and midyear";
cout << endl << "and then calculates the average by what they are worth by";
cout << endl << "the quizes together are worth 25% and midyear counts for 25%";
cout << endl << "and the final counts for 50%";
cout << endl;
}
void input(record& the_grades)
{
cout << endl;
cout << "Enter quiz 1 grade out of 10 points: ";
cin >> the_grades.quiz1; // gets value for quiz 1
while(the_grades.quiz1 > 10)
{
cout << "ERROR!: Invalid Value"; // Error check loop for quiz 1 and does not allow value for over 10 points
cout << endl;
cout << "Re- Enter Value for quiz 1: ";
cin >> the_grades.quiz1;// re-entered value for quiz 1
cout << endl;
}
cout << endl;
cout << "Enter quiz 2 grade out of 10 points: ";
cin >> the_grades.quiz2; // gets value for quiz 2
while(the_grades.quiz2 > 10) // Error check loop for quiz 2 and does not allow value for over 10 points
{
cout << "ERROR!: Invalid Value";
cout << endl;
cout << "Re- Enter Value for quiz 2: ";
cin >> the_grades.quiz2;// re-entered value for quiz 2
cout << endl;
}
cout << "Enter midyear Exam grade out of 100 points: ";
cin >> the_grades.midyear; // gets value for midyear exam
while(the_grades.midyear > 100) // Error check loop for midyear exam and does not allow value for over 100 points
{
cout << "ERROR!: Invalid Value";
cout << endl;
cout << "Re- Enter Value for Midyear Exam: ";
cin >> the_grades.midyear; // re entered value for midyear exam
cout << endl;
}
cout << endl;
cout << "Enter Final Exam grade out of 100 points: ";
cin >> the_grades.final; //gets value for final exam
while(the_grades.final > 100) // Error check loop for Final exam and does not allow value for over 100 points
{
cout << "ERROR!: Invalid Value";
cout << endl;
cout << "Re- Enter Value for Final Exam: ";
cin >> the_grades.final;// re-entered value for final exam
cout << endl;
}
cout << endl;
}
void output(record& the_grades)
{
the_grades.quiz_average = (((the_grades.quiz1/10) + (the_grades.quiz2/10))/2) * .25;
the_grades.final_one = (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_one + the_grades.midyear_one) * 100;
cout << endl << endl;
cout <<"Quiz1: "<< (the_grades.quiz1/10)* 100 <<"% "; //displays quiz one percentage
cout << endl;
cout <<"Quiz2: "<< (the_grades.quiz2/10) * 100 <<"% ";//displays quiz two percentage
cout << endl;
cout <<"Midyear exam: " << the_grades.midyear<<"/100"; // displays midyear exam percentage
cout << endl;
cout <<"Final exam: " << the_grades.final<<"/100"; // displays final exam percentage
cout << endl;
cout <<"Final grade: "<< the_grades.total_grade <<" %"; // displays the final grade in percentage
cout << endl;
cout <<"Letter grade: ";
if(the_grades.total_grade <= 60.0) // if statesments to check which letter grade is recieved
{
cout << "F";
}
if((the_grades.total_grade >= 60.0)&&(the_grades.total_grade < 70.0))
{
cout << "D";
}
if((the_grades.total_grade >= 70.0)&&(the_grades.total_grade < 80.0))
{
cout << "C";
}
if((the_grades.total_grade >= 80.0)&&(the_grades.total_grade < 90.0))
{
cout << "B";
}
if(the_grades.total_grade >= 90.0)
{
cout << "A";
}
cout << endl;
}
Explanation / Answer
#includeusing namespace std; class record //contains values that are recorded { private: double quiz1; double quiz2; double midyear, midyear_one; double final, final_one; double quiz_average; char final_grade; double total_grade; public: void instructions() { coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.