New with classes. Could someone please look at this prgm.

I'm trying to write a program using classes (you don't need classes to write this program but I want to acquaint myself with classes) that outputs a students letter grade and percent earned in a class. The grade is dependent on 2 quizzes (12.5% of final grade ea.), midterm (25% of final grade), final (50% of final grade). The quizzes are out of 10 points ea. and the final/midterm is out of 100 points. Could someone please give me feedback on whether I did this program "correctly" (by which I mean whether it's efficient or if I could trim it down some and/or make it more readable). This is my first program using classes and although it's one of the easier ones I'm unsure of myself when it comes to classes. Thank you ahead of time -- any feedback is appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>

using namespace std;

const double FINAL_WEIGHT = .5, MID_WEIGHT = .25 , QUIZ_WEIGHT = .125;
const double QUIZ_MAX_PTS = 10, FINAL_MAX_PTS = 100, MID_MAX_PTS = 100;

class grade_stats
{
public:
	void output();

	grade_stats(short quiz1_pts, short quiz2_pts, short midterm_pts, short final_pts);
	grade_stats();

private:
	char letter_grade;
	short percent_grade;

	char class_grade(double percent);
};

int main()
{
	cout << "Input the grades of the first two quizzes (0-10): ";
	short quiz1_pts, quiz2_pts;
	cin >> quiz1_pts >> quiz2_pts;
	cout << "Input the grade of the midterm exam (0-100): ";
	short midterm_pts;
	cin >> midterm_pts;
	cout << "Input the grade of the final exam (0-100): ";
	short final_pts;
	cin >> final_pts;
	grade_stats student(quiz1_pts, quiz2_pts, midterm_pts, final_pts);
	student.output();

	cout << "Enter a key to exit: ";
	cin.ignore();
	cin.clear();
	char next;
	cin.get(next);

	return 0;
}

grade_stats::grade_stats(short quiz1_pts, short quiz2_pts, short mid_term_pts, short final_pts)
{
	percent_grade = (FINAL_WEIGHT*(final_pts/FINAL_MAX_PTS) + QUIZ_WEIGHT*(quiz1_pts/QUIZ_MAX_PTS)
		            + QUIZ_WEIGHT*(quiz2_pts/QUIZ_MAX_PTS) + MID_WEIGHT*(mid_term_pts/MID_MAX_PTS)) * 100;
	letter_grade = class_grade(percent_grade);
}

grade_stats::grade_stats() : letter_grade('F'), percent_grade(0)
{
	//default constructor
}

void grade_stats::output()
{
	cout << "The student is getting a " << percent_grade << "%" << endl;
	cout << "This corresponds to a";
	if(letter_grade == 'A' || letter_grade == 'F')
	{
		cout << "n";
	}
	cout << " " << letter_grade << endl;
}

char grade_stats::class_grade(double percent)
{
	if(percent_grade < 60)
	{
		return 'F';
	}
	else if(percent_grade < 70)
	{
		return 'D';
	}
	else if(percent_grade < 80)
	{
		return 'C';
	}
	else if(percent_grade < 90)
	{
		return 'B';
	}
	else
	{
		return 'A';
	}
}
Could someone please comment on my code. I want to know anything wrongly I did so that I don't foster any bad habits when writing codes with classes.
Topic archived. No new replies allowed.