-
Notifications
You must be signed in to change notification settings - Fork 0
/
40_multilevel_inheritance.cpp
100 lines (79 loc) · 2.13 KB
/
40_multilevel_inheritance.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
97
98
99
100
#include <iostream>
using namespace std;
class Student
{
protected:
int roll_number;
public:
void set_roll_number(int);
void get_roll_number(void);
};
void Student ::set_roll_number(int r)
{
roll_number = r;
}
void Student ::get_roll_number()
{
cout << "The roll number is: " << roll_number << endl;
}
class Exam : public Student
{
protected:
float maths, hindi, english, social_sci, science, sanskrit;
public:
void set_marks(float, float, float, float, float, float);
void get_marks();
};
void Exam ::set_marks(float m1, float m2, float m3, float m4, float m5, float m6)
{
maths = m1;
hindi = m2;
english = m3;
social_sci = m4;
science = m5;
sanskrit = m6;
}
void Exam ::get_marks()
{
cout << "The marks obtained in maths: " << maths << endl;
cout << "The marks obtained in hindi: " << hindi << endl;
cout << "The marks obtained in english: " << english << endl;
cout << "The marks obtained in social_science: " << social_sci << endl;
cout << "The marks obtained in science: " << science << endl;
cout << "The marks obtained in sanskrit: " << sanskrit << endl;
}
class Result : public Exam
{
float percentage;
public:
void display_result()
{
get_roll_number();
get_marks();
cout << "The percentage is: " << (maths + hindi + english + social_sci + science + sanskrit) / 6 << "%" << endl;
}
};
int main()
{
int r;
float m, h, e, ss, s, sk;
cout << "Enter your Roll Number: " << endl;
cin >> r;
cout << "Enter your marks in maths: " << endl;
cin >> m;
cout << "Enter your marks in hindi: " << endl;
cin >> h;
cout << "Enter your marks in english: " << endl;
cin >> e;
cout << "Enter your marks in social-science: " << endl;
cin >> ss;
cout << "Enter your marks in science: " << endl;
cin >> s;
cout << "Enter your marks in sanskrit: " << endl;
cin >> sk;
Result atul;
atul.set_roll_number(r);
atul.set_marks(m, h, e, ss, s, sk);
atul.display_result();
return 0;
}