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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
#include <iostream>
using namespace std;
class Employee
{
char name[20];
public:
Employee(const char name[20] = "anonymous")
{
strcpy_s(this->name, 20, name);
}
void GetInfo()
{
cout << "name : " << name << endl;
}
virtual double GetPay() = 0;
virtual void ShowSalaryInfo() = 0;
};
//정규직 클래스(고용직)
class PermanentWorker : public Employee
{
char type[16] = "PermanentWorker";
int salary;
public:
PermanentWorker(const char name[20], int salary) : Employee(name) {
this->salary = salary;
}
void ShowSalaryInfo()
{
GetInfo();
cout << "type : " << type << endl;
cout << "salary : " << GetPay() << endl;
cout << endl;
}
double GetPay()
{
return salary;
}
};
//영업직 클래스
class SalesWorker : public PermanentWorker
{
char type[12] = "SalesWorker";
double incentive;
int salesResult;
public:
SalesWorker(const char name[20], int salary, double incentive) : PermanentWorker(name, salary)
{
salesResult = 0;
this->incentive = incentive;
}
void AddSalesResult(int i)
{
salesResult += i;
}
void ShowSalaryInfo()
{
GetInfo();
cout << "type : " << type << endl;
cout << "salary : " << GetPay() << endl;
cout << endl;
}
double GetPay()
{
return PermanentWorker::GetPay() + incentive * salesResult;
}
};
//해외 영업직 클래스
class ForeignSalesWorker : public SalesWorker
{
char type[19] = "ForeignSalesWorker";
char riskRank;
public:
ForeignSalesWorker(const char name[20], int salary, double incentive, char riskRank) : SalesWorker(name, salary, incentive)
{
this->riskRank = riskRank;
}
void ShowSalaryInfo()
{
GetInfo();
cout << "type : " << type << endl;
cout << "salary : " << GetPay() << endl;
cout << endl;
}
double GetPay()
{
double pay = SalesWorker::GetPay();
if (riskRank == 'A') {
return pay * 1.3;
}
else if (riskRank == 'B') {
return pay * 1.2;
}
else if (riskRank == 'C')
{
return pay * 1.1;
}
else
{
throw range_error("rank out of range");
}
}
};
//임시직 클래스
class TemporaryWorker : public Employee
{
char type[16] = "TemporaryWorker";
int payPerHour;
int workTime;
public:
TemporaryWorker(const char name[20], int perPay) : Employee(name)
{
workTime = 0;
this->payPerHour = perPay;
}
void AddWorkTime(int workTime)
{
this->workTime += workTime;
}
void ShowSalaryInfo()
{
GetInfo();
cout << "type : " << type << endl;
cout << "salary : " << GetPay() << endl;
cout << endl;
}
double GetPay()
{
return payPerHour * workTime;
}
};
//컨트롤 클래스
class EmployeeHandler
{
Employee* empList[50];
int empNum;
public:
EmployeeHandler()
{
empNum = 0;
}
~EmployeeHandler()
{
for (int i = 0; i < empNum; i++)
{
delete empList[i];
}
}
void AddEmployee(Employee* worker)
{
empList[empNum] = worker;
empNum++;
}
void ShowTotalSalary()
{
double sum = 0;
for (int i = 0; i < empNum; i++) {
sum += empList[i]->GetPay();
}
cout << "전 직원 월급 총합 : " << sum << endl;
}
//각 직원의 내역 출력
void ShowAllSalaryInfo() {
for (int i = 0; i < empNum; i++) {
empList[i]->ShowSalaryInfo();
}
}
};
int main(void)
{
EmployeeHandler emp;
//정규직 직원
emp.AddEmployee(new PermanentWorker("kim", 1000));
emp.AddEmployee(new PermanentWorker("lee", 1500));
emp.AddEmployee(new PermanentWorker("jun", 2000));
//영업직 직원
SalesWorker* seller = new SalesWorker("Hong", 1000, 0.1);
seller->AddSalesResult(7000);
emp.AddEmployee(seller); //이름 기본급 인센티브
//해외 영업직 직원
ForeignSalesWorker* fseller1 = new ForeignSalesWorker("Hong", 1000, 0.1, 'A'); //이름 기본급 인센티브 위험도
fseller1->AddSalesResult(7000);
emp.AddEmployee(fseller1);
ForeignSalesWorker* fseller2 = new ForeignSalesWorker("Yoon", 1000, 0.1, 'B'); //이름 기본급 인센티브 위험도
fseller2->AddSalesResult(7000);
emp.AddEmployee(fseller2);
ForeignSalesWorker* fseller3 = new ForeignSalesWorker("Lee", 1000, 0.1, 'C'); //이름 기본급 인센티브 위험도
fseller3->AddSalesResult(7000);
emp.AddEmployee(fseller3);
//임시직 직원
TemporaryWorker* alba = new TemporaryWorker("Jung", 70); //이름 시간당Pay
alba->AddWorkTime(50);
emp.AddEmployee(alba);
emp.ShowAllSalaryInfo(); //각 직원의 내역 출력
emp.ShowTotalSalary(); //전 직원 월급총합
return 0;
}
|