-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOops_apnacollage_3.cpp
More file actions
205 lines (159 loc) · 2.86 KB
/
Copy pathOops_apnacollage_3.cpp
File metadata and controls
205 lines (159 loc) · 2.86 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include<iostream>
#include<string>
using namespace std;
// multi- level inheritance
class Person{
public:
string name;
int age;
};
class Student : public Person{
public:
int rollno;
};
class GradStudent : public Student{
public:
string researchArea;
};
// multiple inheritance
class Student2{
public:
string name;
int rollno;
};
class Teacher{
public:
string subject;
double salary;
};
class TA : public Student2 , public Teacher {
};
// hierarchial inheritance
class Person2{
public:
string name;
int age;
};
class Student3 : public Person2{
public:
int rollno;
};
class Teacher2 : public Person2{
public:
string subject;
};
// polymorphism
class Student4{
public:
string name;
Student4(){
cout << "non-parameterized" << endl;
}
Student4(string name){
this->name = name;
cout << "parameterized" << endl;
}
};
// function overriding
class Parent3{
public:
void getInfo(){
cout << "parent class\n ";
}
};
class Child : public Parent3{
public:
void getInfo(){
cout << "child class\n";
}
};
// abstract classes
class Shape{
virtual void draw() = 0; // pure virtual function
};
class Circle : public Shape{
public:
void draw(){
cout << "drawing a circle\n";
}
};
// for static keywords
void fun(){
static int x =0; // init statment -1 run
cout << "x : " << x << endl;
x++;
}
// static keywords with class
class A{
public:
int x;
void incX(){
x = x + 1;
}
};
// static objects
class ABC{
public:
ABC(){
cout << "constructor\n";
}
~ABC(){
cout << "destructor\n";
}
};
int main(){
//multi-level inheritance
GradStudent s1;
s1.name = "tony stark";
s1.researchArea = "quantum physics";
cout << s1.name << endl;
cout << s1.researchArea << endl;
cout << endl;
// multiple inheritance
TA t1;
t1.name = "tony stark";
t1.subject = "engineering";
cout << t1.name << endl;
cout << t1.subject << endl;
cout << endl;
// hierarchial inheritance
Teacher2 l1;
l1.name = "sai";
l1.subject = "electronics";
l1.age = 20;
cout << l1.name << endl;
cout << l1.subject << endl;
cout << l1.age << endl;
cout << endl;
//polymorphism
Student4 a1; // non parameterized
//Student4 a1("tony stark"); //papameterized
cout << endl;
// function overriding
Child c1;
c1.getInfo();
Parent3 p1;
p1.getInfo();
cout << endl;
//abstract classes
Circle C1;
C1.draw();
cout << endl;
// static keywords
fun();
fun();
fun();
cout << endl;
// in class static keywords
A obj;
obj.x = 0;
cout << obj.x << endl;
obj.incX();
cout << obj.x << endl;
// static objects
if(true){
static ABC obj;
}
cout << "end of main fnx\n";
return 0;
}