-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinheritance lab 4.cpp
76 lines (64 loc) · 1.39 KB
/
inheritance lab 4.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
#include<bits/stdc++.h>
using namespace std;
class Person{
public:
string name;
int age;
Person(string p2,int age1)
{
name=p2;
age=age1;
cout<<"Person constructor called"<<endl;
}
void display()
{
cout<< name<<endl<< age <<endl;
}
~Person()
{
cout<<"Person constructor called"<<endl;
}
};
class Employee:public Person{
public:
int salary;
Employee(string p2,int age1,int sal):Person(p2,age1)
{
salary=sal;
cout<<"Employee constructor called"<<endl;
}
void display()
{
cout<< name<<endl<< age <<endl<<salary<<endl;
}
~Employee()
{
cout<<"Employee constructor called"<<endl;
}
};
class Manager:public Employee{
public:
string dept;
Manager(string p2,int age1,int sal,string dept1):Employee(p2,age1,sal){
dept=dept1;
cout<<"Manager constructor called"<<endl;
}
void display()
{
cout<< name<<endl<< age <<endl<<salary<<endl<<dept<<endl;
}
~Manager()
{
cout<<"Manager constructor called"<<endl;
}
};
int main()
{
Person p1("Fahian",23);
Employee e1("Bob",35,50000);
Manager m1("Jack",56,70000,"CSE");
m1.display();
e1.display();
p1.display();
return 0;
}