-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path39multi-level.cpp
More file actions
63 lines (58 loc) · 1.09 KB
/
Copy path39multi-level.cpp
File metadata and controls
63 lines (58 loc) · 1.09 KB
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;
class student
{
protected:
int roll_no;
public:
void setRoll_no(int);
void getRoll_no(void);
};
void student ::setRoll_no(int num)
{
roll_no = num;
}
void student ::getRoll_no()
{
cout << "Student Roll Number : " << roll_no << endl;
}
class exam : public student
{
protected:
float maths, physics;
public:
void setMarks(float m, float p)
{
maths = m;
physics = p;
}
void getMarks(void)
{
cout << "Math marks : " << maths << endl;
cout << "Physics marks : " << physics << endl;
}
};
class result : public exam
{
private:
float percentage;
public:
void display()
{
getRoll_no();
cout << "Your percentage is : " << ((maths + physics) / 2 )<<"%"<<endl;
}
};
int main()
{
/*NOTE
The follow of inheritance is Student(A) --> Exam(B) --> Result(C)
A is the base for B and B is the base for C
ABC / A-->B-->C is called the inheritance path
*/
result kid1;
kid1.setRoll_no(24);
kid1.setMarks(86.8, 67.45);
kid1.display();
return 0;
}