forked from MAYANK25402/Hactober-2023-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_inh_emp.cpp
76 lines (60 loc) · 1.49 KB
/
class_inh_emp.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
// C++ code of derived class of Employee like FullTimeEmployee and PartTimeEmployee
#include<iostream>
using namespace std;
class Employee
{
int eid;
string name;
public:
Employee(int i, string n)
{
eid = i;
name = n;
}
int getId(){ return eid; }
string getName(){ return name; }
};
class FullTimeEmployee : public Employee
{
int salary;
public:
FullTimeEmployee(int i, string n, int s) : Employee(i,n)
{
salary = s;
}
int getSalary(){ return salary; }
};
class PartTimeEmployee : public Employee
{
int hours;
public:
PartTimeEmployee(int i, string n, int h) : Employee(i,n)
{
hours = h;
}
int getHours(){ return hours; }
};
int main()
{
int i,i1, s, h;
string n, n1;
cout<<"** Details of Full Time Employee **"<<endl;
cout<<"Employee ID: ";
cin>>i;
cout<<"Name: ";
cin>>n;
cout<<"Salary: ";
cin>>s;
cout<<endl<<"** Details of Part Time Employee **"<<endl;
cout<<"Employee ID: ";
cin>>i1;
cout<<"Name: ";
cin>>n1;
cout<<"Hours working: ";
cin>>h;
FullTimeEmployee e1(i,n,s);
PartTimeEmployee e2(i1,n1,h);
cout<<e1.getName()<<"("<<e1.getId()<<") earns ₹"<<e1.getSalary()<<endl;
cout<<e2.getName()<<"("<<e2.getId()<<") works for "<<e2.getHours()<<" hours"<<endl;
return 0;
}