-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOOPS.cpp
129 lines (104 loc) · 2.78 KB
/
OOPS.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
#include <bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// 2. Abstraction
class AbstractEmployee{
virtual void AskForPormotion() = 0;
};
class Employee: AbstractEmployee{
private:
string School;
int Age;
protected:
string Name;
public:
// 1. Encapusulation
// example of setter
void setName(string name){
Name = name;
}
// example of getter
string getName(){
return Name;
}
void setSchool(string s){
School = s;
}
string getSchool(){
return School;
}
void setAge(int n){
Age = n;
}
int getAge(){
return Age;
}
void Introduce(){
cout << "My name is " << Name << " i am from " << School << " school and my age is " << Age << endl;
}
Employee(string n, string s, int a){
Name = n;
School = s;
Age = a;
}
void AskForPormotion(){
if(Age > 40) cout << Name <<" you are pormoted" << endl;
else cout << Name <<" you can't get pormotation as your age is less than 40" << endl;
}
virtual void work(){
cout << Name << " is working on taskmanager." << endl;
}
};
// 3. Inherantance
class Dev:public Employee{ // Inherantance is private by default
public:
string favLang;
Dev(string n, string s, int a, string lang): Employee(n,s,a){
favLang = lang;
}
void FigBug(){
cout<< Name << " you are in " << getSchool() <<" so fix bug using " << favLang << endl;
}
void work(){
cout << Name << " is writing " << favLang << " code." << endl;
}
};
class Teacher: public Employee{
public:
string Subject;
void prepareLeasson(){
cout << Name << " is preapering " << Subject << " leasson" << endl;
}
Teacher(string n, string s, int a, string subject):Employee(n, s, a) {
Subject = subject;
}
void work(){
cout << Name << " is teaching " << Subject << "." << endl;
}
};
int main()
{
fast;
Employee ep1 = Employee("Windows", "Microsoft", 43);
Employee ep2 = Employee("Preadator", "Acer", 34);
// ep1.Introduce();
// ep2.Introduce();
// ep1.AskForPormotion();
// ep2.AskForPormotion();
Dev d = Dev("MIVI", "IND", 32, "CPP");
// d.Introduce();
// d.FigBug();
Teacher t = Teacher("LOGITECH", "FIITJEE", 23, "JAVASCRIPT");
// t.prepareLeasson();
// t.AskForPormotion();
// ep1.work();
// d.work();
// t.work();
// 4. Polymorphism: The most common use of polymorphism is wen a parent class reference is used to refer to a child class object
Employee* e1 = &d;
Employee* e2 = &t;
e1->work();
e2->work();
return 0;
}