Repository navigation
Expand file tree
/
Copy pathinharitance.cpp
More file actions
181 lines (164 loc) · 3.8 KB
/
Copy pathinharitance.cpp
File metadata and controls
181 lines (164 loc) · 3.8 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//! ________________________________________inheritance___________________________________________________
//?reuseability
//?the deriving a new class from already present old class is call inheritance
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
// class B {
// public:
// int data_;
// B(int d) : data_(d) {
// cout << "B::B(int): " << data_ << endl; }
// ~B() {
// cout << "B::~B(): " << data_ << endl; }
// };
// class D: public B {
// int info_;
// public:
// D(int d, int i) : B(d), info_(i) // ctor-1: Explicit construction of Base
// {
// cout << "D::D(int, int): " << data_ << ", " << info_ << endl; }
// D(int i) : info_(i) // ctor-2: Default construction of Base
// {
// cout << "D::D(int): " << data_ << ", " << info_ << endl; }
// ~D() { cout << "D::~D(): " << data_ << ", " << info_ << endl; }
// };
// int main()
// {
// B b(5);
// // ctor-1: Explicit construction of Base
// D d1(1, 2);
// ctor-2: Default construction of Base
//If base class constructor do not have
//default value Error
//D d2(3);
// return 0;
// }
// class B {
// // output 5 0 0 2 0 2 0 5
// public:
// int data_;
// B(int d = 0) : data_(d) {
// cout << "B::B(int): " << data_ << endl; }
// ~B() {
// cout << "B::~B(): " << data_ << endl; }
// };
// class D: public B {
// int info_;
// public:
// D(int d, int i)
// {
// //B(d);
// info_= i ;
// cout << "D::D(int, int): " << data_ << ", " << info_ << endl;
// }
// D(int i) : info_(i) // ctor-2: Default construction of Base
// { cout << "D::D(int): " << data_ << ", " << info_ << endl; }
// ~D() { cout << "D::~D(): " << data_ << ", " << info_ << endl; }
// };
// int main()
// {
// B b(5);
// D d1(1, 2);
// /*
Now the code will work fine, the only issue is compiler will set data_ variable to 0 (default) rather setting it to 1 (user’s input)
*/
// return 0;
// }
// class Vehicle {
// protected:
// int wheels_count;
// float max_speed;
// string manufacturer;
// Vehicle(int, float, string);
// void vehicle_print();
// };
// Vehicle::Vehicle(int wheels_count, float max_speed,
// string manufacturer):
// wheels_count(wheels_count),
// max_speed(max_speed),
// manufacturer(manufacturer) {
// cout << "Vehicle constructor called\n";
// }
// void Vehicle::vehicle_print() {
// cout << "Wheel Count: " << wheels_count << endl;
// cout << "Max Speed: " << max_speed << endl;
// cout << "Manufacturer: " << manufacturer << endl;
// }
// class Automobile : public Vehicle{
// float engine_cc;
// int gear_count;
// public:
// Automobile(int wheels_count, float max_speed,
// string manufacturer,
// float engine_cc, int gear_count):
// engine_cc(engine_cc),
// gear_count(gear_count),
// Vehicle(wheels_count, max_speed, manufacturer) {
// cout << "Automobile constructor called\n";
// }
// void print() {
// vehicle_print();
// cout << "Engine Capacity: " << engine_cc << endl;
// cout << "Gear Count: " << gear_count << endl;
// }
// };
// int main() {
// Automobile automobile(2, 100, "Honda", 125, 4);
// automobile.print();
// return 0;
// }
class N{
public:
int i;
N(){
cout<<"N";
}
void n(){
cout<<"n";
}
};
class A: public N{
public:
int j;
A(){
cout<<"A";
}
void d(){
cout<<"neha";
}
};
class B : public N {
public :
int k;
B(){
cout<<"B";
}
void w(){
cout<<"helo";
}
};
class C: public A,public B{
public:
int mul;
C(){
cout<<"C";
}
void x(){
}
};
int main(){
C c;
B::c.i=10;
c.j=20;
c.k=30;
c.mul=B::c.i*c.j*c.k;
cout<
// c x;
// x.A;
// x.B;
}