Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
geekblower authored Mar 26, 2023
1 parent 4c24e9c commit c46baa2
Show file tree
Hide file tree
Showing 20 changed files with 1,320 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Lecture-043/01_Inheritance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;

class Human {
public:
int height;
int weight;
int age;
};

class Male : public Human {

};

class Female : protected Human {

};

int main() {
Male m;

cout << "m.height : " << m.height << endl;
cout << "m.weight : " << m.weight << endl;
cout << "m.age : " << m.age << endl;

Female f;
// Not possible
// cout << "f.height : " << f.height << endl;
// cout << "f.weight : " << f.weight << endl;
// cout << "f.age : " << f.age << endl;

return 0;
}
30 changes: 30 additions & 0 deletions Lecture-043/02_Single_Inheritance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <bits/stdc++.h>
using namespace std;

class A {
public:
int base_property1;
int base_property2;
};

class B : public A {
public:
int child_property1;
int child_property2;
};

int main() {
B b1;

b1.base_property1 = 10;
b1.base_property2 = 15;
b1.child_property1 = 20;
b1.child_property2 = 25;

cout << "b1.base_property1 : " << b1.base_property1 << endl;
cout << "b1.base_property2 : " << b1.base_property2 << endl;
cout << "b1.child_property1 : " << b1.child_property1 << endl;
cout << "b1.child_property2 : " << b1.child_property2 << endl;

return 0;
}
40 changes: 40 additions & 0 deletions Lecture-043/03_Multilevel_Inheritance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <bits/stdc++.h>
using namespace std;

class A {
public:
int base_property1;
int base_property2;
};

class B : public A {
public:
int child_property1;
int child_property2;
};

class C : public B {
public:
int new_child_property1;
int new_child_property2;
};

int main() {
C c1;

c1.base_property1 = 10;
c1.base_property2 = 15;
c1.child_property1 = 20;
c1.child_property2 = 25;
c1.new_child_property1 = 30;
c1.new_child_property2 = 35;

cout << "c1.base_property1 : " << c1.base_property1 << endl;
cout << "c1.base_property2 : " << c1.base_property2 << endl << endl;
cout << "c1.child_property1 : " << c1.child_property1 << endl;
cout << "c1.child_property2 : " << c1.child_property2 << endl << endl;
cout << "c1.new_child_property1 : " << c1.new_child_property1 << endl;
cout << "c1.new_child_property2 : " << c1.new_child_property2 << endl;

return 0;
}
40 changes: 40 additions & 0 deletions Lecture-043/04_Multiple_Inheritance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <bits/stdc++.h>
using namespace std;

class A {
public:
int base1_property1;
int base1_property2;
};

class B {
public:
int base2_property1;
int base2_property2;
};

class C : public A, public B {
public:
int child_property1;
int child_property2;
};

int main() {
C c1;

c1.base1_property1 = 10;
c1.base1_property2 = 15;
c1.base2_property1 = 20;
c1.base2_property2 = 25;
c1.child_property1 = 30;
c1.child_property2 = 35;

cout << "c1.base1_property1 : " << c1.base1_property1 << endl;
cout << "c1.base1_property2 : " << c1.base1_property2 << endl << endl;
cout << "c1.base2_property1 : " << c1.base2_property1 << endl;
cout << "c1.base2_property2 : " << c1.base2_property2 << endl << endl;
cout << "c1.child_property1 : " << c1.child_property1 << endl;
cout << "c1.child_property2 : " << c1.child_property2 << endl;

return 0;
}
50 changes: 50 additions & 0 deletions Lecture-043/05_Hybrid_Inheritance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <bits/stdc++.h>
using namespace std;

class A {
public:
int base_property1;
int base_property2;
};

class B : public A {
public:
int child1_property1;
int child1_property2;
};

class C : public A {
public:
int child2_property1;
int child2_property2;
};

class D : public B, public C {
public:
int new_child_property1;
int new_child_property2;
};

int main() {
D d1;

// d1.base_property1 = 50;
// d1.base_property2 = 55;
d1.child1_property1 = 60;
d1.child1_property2 = 65;
d1.child2_property1 = 70;
d1.child2_property2 = 75;
d1.new_child_property1 = 80;
d1.new_child_property2 = 85;

// cout << "d1.base_property1 : " << d1.base_property1 << endl;
// cout << "d1.base_property2 : " << d1.base_property2 << endl << endl;
cout << "d1.child1_property1 : " << d1.child1_property1 << endl;
cout << "d1.child1_property2 : " << d1.child1_property2 << endl << endl;
cout << "d1.child2_property1 : " << d1.child2_property1 << endl;
cout << "d1.child2_property2 : " << d1.child2_property2 << endl << endl;
cout << "d1.new_child_property1 : " << d1.new_child_property1 << endl;
cout << "d1.new_child_property2 : " << d1.new_child_property2 << endl;

return 0;
}
47 changes: 47 additions & 0 deletions Lecture-043/06_Hierarchical_Inheritance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <bits/stdc++.h>
using namespace std;

class A {
public:
int base_property1;
int base_property2;
};

class B : public A {
public:
int child1_property1;
int child1_property2;
};

class C : public A {
public:
int child2_property1;
int child2_property2;
};

int main() {
B b1;
C c1;

b1.base_property1 = 50;
b1.base_property2 = 55;
b1.child1_property1 = 60;
b1.child1_property2 = 65;

c1.base_property1 = 10;
c1.base_property2 = 15;
c1.child2_property1 = 20;
c1.child2_property2 = 25;

cout << "b1.base_property1 : " << b1.base_property1 << endl;
cout << "b1.base_property2 : " << b1.base_property2 << endl << endl;
cout << "b1.child1_property1 : " << b1.child1_property1 << endl;
cout << "b1.child1_property2 : " << b1.child1_property2 << endl << endl;

cout << "c1.base_property1 : " << c1.base_property1 << endl;
cout << "c1.base_property2 : " << c1.base_property2 << endl << endl;
cout << "c1.child2_property1 : " << c1.child2_property1 << endl;
cout << "c1.child2_property2 : " << c1.child2_property2 << endl << endl;

return 0;
}
54 changes: 54 additions & 0 deletions Lecture-043/07_Inheritance_Ambiguity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <bits/stdc++.h>
using namespace std;

class A {
public:
int base_property1;
int base_property2;
};

class B : public A {
public:
int child1_property1;
int child1_property2;
};

class C : public A {
public:
int child2_property1;
int child2_property2;
};

class D : public B, public C {
public:
int new_child_property1;
int new_child_property2;
};

int main() {
D d1;

d1.B::base_property1 = 50;
d1.B::base_property2 = 55;
d1.C::base_property1 = 60;
d1.C::base_property2 = 65;
d1.child1_property1 = 70;
d1.child1_property2 = 75;
d1.child2_property1 = 80;
d1.child2_property2 = 85;
d1.new_child_property1 = 90;
d1.new_child_property2 = 95;

cout << "d1.B::base_property1 : " << d1.B::base_property1 << endl;
cout << "d1.B::base_property2 : " << d1.B::base_property2 << endl << endl;
cout << "d1.C::base_property1 : " << d1.C::base_property1 << endl;
cout << "d1.C::base_property2 : " << d1.C::base_property2 << endl << endl;
cout << "d1.child1_propertn y1 : " << d1.child1_property1 << endl;
cout << "d1.child1_property2 : " << d1.child1_property2 << endl << endl;
cout << "d1.child2_property1 : " << d1.child2_property1 << endl;
cout << "d1.child2_property2 : " << d1.child2_property2 << endl << endl;
cout << "d1.new_child_property1 : " << d1.new_child_property1 << endl;
cout << "d1.new_child_property2 : " << d1.new_child_property2 << endl;

return 0;
}
Empty file.
34 changes: 34 additions & 0 deletions Lecture-043/09_Operator_Overloading.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <bits/stdc++.h>
using namespace std;

class A {
public:
int a, b;

int add() {
return a+b;
}

void operator + (A &obj) {
int value1 = this->a;
int value2 = obj.a;
cout << "Output : " << value2 - value1 << endl;
}

void operator () () {
cout << "Bracket is called by " << this->a << endl;
}
};

int main() {
A obj1, obj2;

obj1.a = 2;
obj2.a = 7;

obj1 + obj2;

obj1();

return 0;
}
26 changes: 26 additions & 0 deletions Lecture-043/10_Runtime_Polymorphism.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;

class A {
public:
void func() {
cout << "Inside Parent Class" << endl;
}
};

class B : public A {
public:
void func() {
cout << "Inside Child Class" << endl;
}
};

int main() {
A obj1;
B obj2;

obj1.func();
obj2.func();

return 0;
}
Empty file added Lecture-043/README.md
Empty file.
Loading

0 comments on commit c46baa2

Please sign in to comment.