-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultilevelInheritance.cpp
63 lines (53 loc) · 984 Bytes
/
MultilevelInheritance.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
#include <iostream>
using namespace std;
// Multilevel Inheritance A--->B--->C
class Student
{
protected:
int roll_no;
public:
void get_roll_no(int r)
{
roll_no = r;
}
void set_roll_no()
{
cout << "roll no: " << roll_no << endl;
}
};
class Exam : public Student
{
protected:
int maths_marks;
int physics_marks;
public:
void get_marks(int m, int p)
{
maths_marks = m;
physics_marks = p;
}
void set_marks()
{
cout << "maths marks: " << maths_marks << endl;
cout << "physics marks: " << physics_marks << endl;
}
};
class Result : public Exam
{
float percentage;
public:
void display()
{
set_roll_no();
set_marks();
cout << "The percentage is :" << (maths_marks + physics_marks) / 2 << endl;
}
};
int main()
{
Result Daniyal;
Daniyal.get_roll_no(6880);
Daniyal.get_marks(95, 98);
Daniyal.display();
return 0;
}