-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultilevelInheritance.cpp
78 lines (64 loc) · 1.41 KB
/
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include<iostream>
using namespace std;
class Student{
protected:
int roll_no;
public:
void set_rollno(int);
void get_rollno();
};
void Student :: set_rollno(int a){
roll_no = a ;
}
void Student :: get_rollno(void){
cout<<"Your Roll no is "<<roll_no<<endl;
}
class Exam : public Student{
protected:
float maths;
float physics;
public:
void set_marks(float , float);
void get_marks();
};
void Exam :: set_marks(float m1 , float p1){
maths = m1 ;
physics = p1 ;
}
void Exam :: get_marks(void){
cout<<"Your Marks in Maths are "<<maths<<endl;
cout<<"Your Marks in Physics are "<<physics<<endl;
}
class Results : public Exam{
float percentage;
public:
void display_result();
};
void Results :: display_result(void){
get_rollno();
get_marks();
cout<<"Your Percentage is "<<(maths+physics)/2<<"%"<<endl;
}
int main(){
Results Anurag;
Anurag.set_rollno(06);
Anurag.set_marks(95 , 85);
Anurag.display_result();
// int r ;
// float m , p ;
// cout<<"Enter Your Roll No : ";
// cin>>r;
// Anurag.set_rollno(r);
// cout<<"Enter the Marks in Maths and Physics : "<<endl;
// cin>>m>>p;
// Anurag.set_marks(m , p);
// Anurag.display_result();
return 0;
}
/*
Output :
Your Roll no is 6
Your Marks in Maths are 95
Your Marks in Physics are 85
Your Percentage is 90%
*/