Construct a C++ grading program for a class with the following grading policies:
ID: 3877886 • Letter: C
Question
Construct a C++ grading program for a class with the following grading policies:-
a. There are two quizzes, each quizzes is worth 10 points.
b. There is one mid semester test and one final test, each is worth 100 points.
c. The final test accounts for 50 percent of the grade, the mid semester test accounts for 25 percent of the grade and the two quizzes together count for another total 25 percent.
Grading system is as follows:-
>90 A
>=80 and <90 B
>=70 and <80 C
>=60 and <70 D
<60 E
The program should read in the student's scores and output the student's record, which consists of two quiz and two exam scores as well as the student's average numeric score for the entire course and the final letter grade. Make the StudentRecord type a class type rather than a struct, name the class SR. The student record class should have member variables for all input data described and a member variable for the student's weighted average numeric score for the entire course as well as a member variable for the student's 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 student's final letter grade and sets the corresponding member variable.
Use these functions to create the program.
void ENTER(S& st); // Asks the user to input for one student and sets the structure variable members.//
void A(S& st); //use this to determine the numeric average and letter grade.//
void R(const S st); //outputs the student record.
Sample Output:-
Sample data for the test run:-
1 7 10 90 95
2 9 8 90 80
3 7 8 70 80
4 5 8 50 70
5 4 0 40 35
Output:
input student #: 1
input the two quiz scores
7 10
Input midsemester test and final test scores
90 95
input student #: 2
input the two quiz scores
9 8
Input midsemester test and final test scores
90 80
input student #3
input the two quiz scores
7 8
Input midsemester test and final test scores
70 80
input student # 4
input the two quiz scores
5 8
Input midsemester test and final test scores
50 70
input student # 5
input the two quiz scores
4 0
Input midsemester test and final test scores
40 35
Record for student # : 1
Quiz scores : 7 10
Midsemester test and final test scores: 90 95
Average: 91.25
Letter grade earned is A
Record for student #: 2
Quiz Scores: 9 8
Midsemester test and final test scores: 90 80
Average: 83.75
Letter grade earned is B
Record for student #: 3
Quiz Scores: 7 8
Midsemester test and final test scores: 70 80
Average: 76.25
Letter Grade earned is C
Record for student: 4
Quiz Scores: 5 8
Midsemester test and final test scores: 50 70
Average: 63.75
Letter Grade earned is D
Record for student #: 5
Quiz Scores: 4 0
Midsemester and final test scores: 40 35
Average: 32.5
Letter Grade is earned is F
Explanation / Answer
Solution:
code:
//Include this header file, while using visual studio.
#include "stdafx.h"
//Include the required header file.
#include <iostream>
#include <string>
//Use the standard naming convention.
using namespace std;
//Define the structure to store the student's information.
struct Student
{
//Declare the required variables.
double quiz_score_1;
double quiz_score_2;
double mid_term_score;
double finalexam_score;
double avgOfScores;
char finalGrade;
};
//Declare the required functions.
double inputScores(string, int);
char computeFinalGrade(double);
//Start the execution of main() method.
int main()
{
//Declare a structure variable to store the student's
//details.
Student stu;
//Prompt the user to enter the scores for all the
//quizes, mid-exams, and final exams.
cout << "Enter the scores of the student: ";
//Call the function inputScores() to get the scores
//for the quizez, mid-exams, and final exam.
stu.quiz_score_1 = inputScores("quiz 1", 10);
stu.quiz_score_2 = inputScores("quiz 2", 10);
stu.mid_term_score = inputScores("mid term exam",
100);
stu.finalexam_score = inputScores("final exam", 100);
//Display the details of the student's scores and
//grade.
cout << " ----Student Final Report---- ";
cout << "Score for the quiz 1: " << stu.quiz_score_1
<< endl;
cout << "Score for the quiz 2: " << stu.quiz_score_2
<< endl;
cout << "Score for the mid term exam: " <<
stu.mid_term_score << endl;
cout << "Score for the final exam: " <<
stu.finalexam_score << endl;
//Calculate the average of the scores in percentage.
//The weightage of final exam, mid term exam, and both
//quizes is 50 %, 25 %, and 25 %respectively.
stu.avgOfScores = (stu.quiz_score_1 +
stu.quiz_score_2) / 20 * 100 * .25 +
stu.mid_term_score*.25 + stu.finalexam_score*.5;
//Call the function computeFinalGrade() to get the
//final grade corresponding to the average of scores.
stu.finalGrade = computeFinalGrade(stu.avgOfScores);
//Display the average of scores of all examinations in
//percentage and final grade of teh student.
cout << "The average percentage of the scores of the";
cout << " student is: " << stu.avgOfScores << endl;
cout << "The final grade of the student is: " <<
stu.finalGrade << endl;
//Use this command while using visual studio.
system("pause");
return 0;
}
//Define the method computeFinalGrade().
char computeFinalGrade(double avgScore)
{
//Declare the required variable.
char grade;
//If the average score is more than or equal to 90,
//then the final grade will be A.
if (avgScore >= 90)
grade = 'A';
//If the average score is more than or equal to 80 and
//less than 90, then the final grade will be B.
else if (avgScore < 90 && avgScore >= 80)
grade = 'B';
//If the average score is more than or equal to 70 and
//less than 80, then the final grade will be C.
else if (avgScore < 80 && avgScore >= 70)
grade = 'C';
//If the average score is more than or equal to 60 and
//less than 70, then the final grade will be D.
else if (avgScore < 70 && avgScore >= 60)
grade = 'D';
//If the average score is less than 60, then the final
//grade will be F.
else if (avgScore < 90)
grade = 'F';
//Return the final grade.
return grade;
}
//Define the function inputScores().
double inputScores(string exams, int max_marks)
{
//Declare the required variables.
int marks;
//Prompt the user to enter the score for an exam.
cout << "Enter the score for " << exams << ": ";
cin >> marks;
//Check if the score is in a valid range.
while (marks < 0 || marks > max_marks)
{
//Display an appropriate message and prompt the
//user again for the score.
cout << "Please enter the valid score between 0";
cout << " and " << max_marks << " ";
cout << "Enter the score for " << exams << ": ";
cin >> marks;
}
//Return the score of the student.
return marks;
}
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)