I recently got an assignment that tasks me to create a class which contains private variables and member functions/void functions. Classes have just been introduced to me and my teacher gave me an assignment that I don't really understand. The issue I'm having is that the average and letter grade aren't correctly being outputted as shown below. Everything has to take place within the member functions. Also, am I using the member functions correctly? I've seen online that they are being defined within the class but in my notes I see that they are referenced and treated just like a user defined function. The confusion I'm having is this part of the assignment:
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
My code is below:
#include <iostream>
#include <cmath>
using namespace std;
class student_records
{
private:
double quiz1, quiz2, midterm_exam, final_exam;
float weighted_avg;
char final_grade;
public:
void setquiz1 (double q1)
{
quiz1 = q1;
}
void setquiz2 (double q2)
{
quiz2 = q2;
}
void setmidterm_exam (double mid)
{
midterm_exam = mid;
}
void setfinal_exam (double finale)
{
final_exam = finale;
}
void input()
{
cout << "Welcome to the Grading Program! Please enter the following information\n";
cout << "Enter Quiz 1 and 2 results out of 10 points: ";
cin >> quiz1 >> quiz2;
cout << "Enter Mid-term result out of 100 points: ";
cin >> midterm_exam;
cout << "Enter Final exam result out of 100 points: ";
cin >> final_exam;
}
void weightavg ()
{
weighted_avg = ((quiz1 + quiz2)/20 * 0.25 + midterm_exam / 100 * 0.25 + final_exam / 100 * 0.5) * 100;
}
void finalg ()
{
if (weighted_avg >= 90)
{
final_grade = 'A';
}
else if (weighted_avg >= 80)
{
final_grade = 'B';
}
else if (weighted_avg >= 70)
{
final_grade = 'C';
}
else if (weighted_avg >= 60)
{
final_grade = 'D';
}
else
{
final_grade = 'F';
}
}
double getquiz1 ()
{
return (quiz1);
}
double getquiz2 ()
{
return (quiz2);
}
double getmidterm_exam ()
{
return (midterm_exam);
}
double getfinal_exam ()
{
return (final_exam);
}
double getweighted_avg ()
{
return (weighted_avg);
}
double getfinalg ()
{
return (final_grade);
}
};
int main()
{
student_records values, final_avg, grade, s;
values.input();
final_avg.weightavg();
grade.finalg();
cout << "The average is " << s.getweighted_avg() << " and your final grade is " << s.getfinalg();
return 0;
}
Output is:
Welcome to the Grading Program! Please enter the following information
Enter Quiz 1 and 2 results out of 10 points: 10
10
Enter Mid-term result out of 100 points: 100
Enter Final exam result out of 100 points: 100
The average is 1.46101e-38 and your final grade is 0