-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlab3_q6.cpp
More file actions
115 lines (105 loc) · 2.73 KB
/
lab3_q6.cpp
File metadata and controls
115 lines (105 loc) · 2.73 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
/*
6. Employee class contain details like name,emp no,pay rate, constructor function and a
pay() function. Manager class inherits from employee and has the option of drawing pay
on hourly basis or salary basis and has an additional data is salaried(bool). Class
Supervisor is derived from employee and has an additional field department and is
always salaried. Base and both derived classes should contain pay() function with same
name.
*/
#include <iostream>
#include <string.h>
using namespace std;
int const totalWorkingHours = 160;
class Employee
{
protected:
char name[10];
int empNo;
float payRate;
public:
Employee() {}
void getEmployeetData()
{
cout << "Enter the employee details below" << endl;
cout << "--------------------------------" << endl;
cout << "Enter the name:" << endl;
cin >> name;
cout << "Enter employment no." << endl;
cin >> empNo;
cout << "Enter pay rate:" << endl;
cin >> payRate;
}
virtual float pay() = 0;
void displayEmployeeData()
{
cout << "*******" << endl;
cout << "Name of employee: " << name << endl;
cout << "Employment No. " << empNo << endl;
cout << "Pay rate " << payRate << endl;
cout << "Salary: " << pay() << endl;
cout << "********" << endl;
}
};
class Manager : public Employee
{
private:
bool isSalaried;
int workingHours;
public:
void getManagerData()
{
cout << "If salaried hourly enter 0 else 1:" << endl;
cin >> isSalaried;
if (!isSalaried)
{
cout << "Enter the total working hours:" << endl;
cin >> workingHours;
}
}
float pay()
{
if (isSalaried)
return payRate * totalWorkingHours;
else
return payRate * workingHours;
}
};
class Supervisor : public Employee
{
private:
string department;
public:
void getSupervisorData()
{
cout << "\n Department: ";
cin >> department;
}
float pay()
{
return payRate * totalWorkingHours;
}
};
int main()
{ Manager M1;
Supervisor S;
int choice;
cout << "\n **enter details** ";
cout << "\n 1. Manager";
cout << "\n 2. Supervisor";
cout << "\n Enter your choice(1 or 2): ";
cin >> choice;
switch (choice)
{ case 1:
M1.getEmployeetData();
M1.getManagerData();
M1.displayEmployeeData();
break;
case 2:
S.getEmployeetData();
S.getSupervisorData();
S.displayEmployeeData();
break;
default:cout << "\n Incorrect Choice!";
};
return 0;
}