-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInheritance
136 lines (127 loc) · 2.48 KB
/
Inheritance
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Online C++ compiler to run C++ program online
#include <iostream>
#include<string.h>
using namespace std;
class Student{
private:
int roll_no;
protected:
char section [10];
public:
void get_rno(){
cout << "\n enter the roll no: ";
cin >> roll_no;
}
void show_rno(){
cout << "roll no: " << roll_no;
}
};
class result:protected Student{
private:
float fees;
public:
void get_data(){
get_rno();
cout << "\n enter fees: " ;
cin >> fees;
cout << "enter serction: ";
cin >> section;
}
void display(){
show_rno();
cout << "\n fees: " << fees;
cout << "\n section: " << section;
}
};
int main() {
result obj1;
obj1.get_data();
obj1.display();
//obj1.get_rno();
//obj1.show_rno();
// obj1.roll_no = 78;
return 0;
}
=========================================================================
// multiple inheritance
#include <iostream>
using namespace std;
class M{
protected:
int m;
public:
void get_m(int){
}
};
class N{
protected:
int n;
public:
void get_n(int){
}
};
class P:public M , public N{
public:
void display(void);
};
void M :: get_m(int x){
m = x;
}
void N :: get_n(int y){
n = y;
}
void P :: display(void){
cout << "m = " << m << endl;
cout << "n : " << n << endl;
cout << "m * n = " << m * n << endl;
}
int main(){
P p;
p.get_m(10);
p.get_n(5);
p.display();
}
return 0;
}
======================================================================================================
// multilevel inheritance
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;
class M{
protected:
int m;
public:
void get_m(int){
}
};
class N{
protected:
int n;
public:
void get_n(int){
}
};
class P:public M , public N{
public:
void display(void);
};
void M :: get_m(int x){
m = x;
}
void N :: get_n(int y){
n = y;
}
void P :: display(void){
cout << "m = " << m << endl;
cout << "n : " << n << endl;
cout << "m * n = " << m * n << endl;
}
int main(){
P p;
p.get_m(10);
p.get_n(5);
p.display();
}
return 0;
}