-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrough1.cpp
151 lines (123 loc) · 2.52 KB
/
rough1.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// #include <bits/stdc++.h>
// using namespace std;
// // Base class - 1
// class parent1
// {
// public:
// int num = 10;
// string name = "Lokesh";
// };
// // Base Class - 2
// class parent2
// {
// public:
// int num1, num2;
// public:
// void get_data()
// {
// cout << "Enter the value of Num1 and Num2 " << endl;
// cin >> num1 >> num2;
// }
// void show_data()
// {
// cout << "The Number1 is : " << num1 << endl;
// cout << "The Number2 is : " << num2 << endl;
// }
// };
// // Child/Derived/Sub class
// class Child1 : public parent1, public parent2
// {
// public:
// void sumParent2()
// {
// cout << "The sum of 2 Numbers of Parent2 class is : " << num1 + num2 << endl;
// }
// void print_data()
// {
// cout << "The name is : " << name << endl;
// cout << "The number is : " << num << endl;
// }
// };
// int main()
// {
// Child1 c1;
// c1.print_data();
// c1.get_data();
// c1.show_data();
// c1.sumParent2();
// return 0;
// }
// Multilevel Inheritance
// #include <bits/stdc++.h>
// using namespace std;
// class Baba
// {
// protected:
// int rupya1 = 1000;
// int rupya2 = 10000;
// Baba(){
// cout<<"I'm the constructor of papa's papa class\n";
// }
// };
// class Papa : protected Baba
// {
// public:
// int dollar = 5000;
// Papa(){
// cout<<"I'm the constructor of papa class\n";
// }
// };
// class hum : public Papa
// {
// public:
// hum(){
// cout<<"My baba has "<<rupya1<<" "<<rupya2<<" as his salary"<<endl;
// cout<<"My papa's salary in dollar is : "<<dollar<<endl;
// }
// };
// int main()
// {
// hum h1;
// return 0;
// }
// Hierarchical Inheritance
#include <bits/stdc++.h>
using namespace std;
// Parent class
class Baba
{
protected:
int rupya1 = 1000;
int rupya2 = 10000;
};
// Child - 1
class Papa : protected Baba
{
public:
int dollar = 5000;
Papa(){
cout<<"I'm the constructor of papa class\n";
}
void show_data(){
cout<<"My baba has "<<rupya1<<" "<<rupya2<<" as his salary"<<endl;
cout<<"My salary in dollars is : "<<dollar<<endl;
}
};
// Child 2
class hum : public Baba
{
public:
hum(){
cout<<"My baba has "<<rupya1<<" "<<rupya2<<" as his salary"<<endl;
}
};
// Main Class
int main()
{
// Child1 Object
hum h1;
// Child2 Object
Papa p;
p.show_data();
return 0;
}