검색결과 리스트
글
8-3 연습문제
#include <iostream>
#include <cstring>
using namespace std;
class Employee
{
private:
char name[100];
public:
Employee(const char * name)
{
strcpy(this->name, name);
}
void ShowYourName() const
{
cout << "name: " << name << endl;
}
virtual int GetPay() const
{
return 0;
}
virtual void ShowSalaryInfo() const
{ }
};
class PermanentWorker : public Employee
{
private:
int salary;
public:
PermanentWorker(const char * name, int money)
: Employee(name), salary(money)
{ }
int GetPay() const
{
return salary;
}
void ShowSalaryInfo() const
{
ShowYourName();
cout << "salary: " << GetPay() << endl << endl;
}
};
class TemporaryWorker : public Employee
{
private:
int workTime;
int payPerHour;
public:
TemporaryWorker(const char * name, int pay)
: Employee(name), workTime(0), payPerHour(pay)
{ }
void AddWorkTime(int time)
{
workTime += time;
}
int GetPay() const
{
return workTime * payPerHour;
}
void ShowSalaryInfo() const
{
ShowYourName();
cout << "salary: " << GetPay() << endl << endl;
}
};
class SalesWorker : public PermanentWorker
{
private:
int salesResult; // 월 판매실적
double bonusRatio; // 상여금 비율
public:
SalesWorker(const char * name, int money, double ratio)
: PermanentWorker(name, money), salesResult(0), bonusRatio(ratio)
{ }
void AddSalesResult(int value)
{
salesResult += value;
}
int GetPay() const
{
return PermanentWorker::GetPay()
+ (int)(salesResult*bonusRatio);
}
void ShowSalaryInfo() const
{
ShowYourName();
cout << "salary: " << GetPay() << endl << endl;
}
};
class EmployeeHandler
{
private:
Employee * empList[50];
int empNum;
public:
EmployeeHandler() : empNum(0)
{ }
void AddEmployee(Employee* emp)
{
empList[empNum++] = emp;
}
void ShowAllSalaryInfo() const
{
for (int i = 0; i<empNum; i++)
empList[i]->ShowSalaryInfo();
}
void ShowTotalSalary() const
{
int sum = 0;
for (int i = 0; i<empNum; i++)
sum += empList[i]->GetPay();
cout << "salary sum: " << sum << endl;
}
~EmployeeHandler()
{
for (int i = 0; i<empNum; i++)
delete empList[i];
}
};
int main(void)
{
// 직원관리를 목적으로 설계된 컨트롤 클래스의 객체생성
EmployeeHandler handler;
// 정규직 등록
handler.AddEmployee(new PermanentWorker("JUN", 2000));
handler.AddEmployee(new PermanentWorker("LEE", 3500));
// 임시직 등록
TemporaryWorker * alba = new TemporaryWorker("Jung", 1800);
alba->AddWorkTime(5); // 5시간 일한결과 등록
handler.AddEmployee(alba);
// 영업직 등록
SalesWorker * sell = new SalesWorker("Hong", 2000, 0.2);
sell->AddSalesResult(7000); // 영업실적 7000
handler.AddEmployee(sell);
// 이번 달에 지불해야 할 급여의 정보
handler.ShowAllSalaryInfo();
// 이번 달에 지불해야 할 급여의 총합
handler.ShowTotalSalary();
return 0;
}
'☆C언어 > 소스' 카테고리의 다른 글
c++ q (0) | 2018.09.19 |
---|---|
문자열 숫자 쉽게 숫자로 바꾸기 (0) | 2017.12.25 |
'q' 입력시 종료 (0) | 2017.11.21 |
달력 (0) | 2017.11.13 |
괄호 검사 (0) | 2017.06.17 |