-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC++ Classes Introduction.cpp
96 lines (86 loc) · 1.64 KB
/
C++ Classes Introduction.cpp
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
92
93
94
95
96
//{ Driver Code Starts
// Initial Template for C++
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
// User function Template for C++
// CollegeCourse Class
class CollegeCourse
{
public:
string courseId;
char grade;
int credits;
void set_CourseId(string CID)
{
courseId = CID;
}
void set_Grade(char g)
{
grade = g;
}
void set_Credit(int cr)
{
credits = cr;
}
int calculateGradePoints(char g)
{
if (g == 'A' || g == 'a')
{
grade = 10;
}
else if (g == 'B' || g == 'b')
{
grade = 9;
}
else if (g == 'C' || g == 'c')
{
grade = 8;
}
else if (g == 'D' || g == 'd')
{
grade = 7;
}
else if (g == 'E' || g == 'e')
{
grade = 6;
}
else
{
grade = 5;
}
return grade;
}
float calculateHonorPoints(int gp, int cr)
{
return grade * credits;
}
void display()
{
cout << int(grade)<<" ";
cout << grade * credits << endl;
}
};
//{ Driver Code Starts.
int main()
{
int t;
cin >> t;
while (t--)
{
CollegeCourse cc;
string courseId;
int gp;
char grade;
int credits;
cin >> courseId >> grade >> credits;
cc.set_CourseId(courseId);
cc.set_Grade(grade);
cc.set_Credit(credits);
gp = cc.calculateGradePoints(grade);
cc.calculateHonorPoints(gp, credits);
cc.display();
}
return 0;
}
// } Driver Code Ends