본문 바로가기
C++/열혈 C++

열혈 C++ 연습문제 8-3

by Beijing_KingGod 2018. 4. 8.
#include<iostream>
using namespace std;
//entity class
/*****************Employee****************/
class Employee
{
protected:
	char name[20];
public:
	Employee(char* _name);
	const char* GetName();
	virtual int GetPay()=0; // 순수 가상함수
};
Employee::Employee(char* _name)
{
	strcpy(name,_name);
}
const char* Employee::GetName()
{
	return name;
}

/*****************Permanent****************/
class Permanent : public Employee
{
protected:
	int salary; //기본 급여
public:
	Permanent(char* _name, int sal);
	int GetPay();
};
Permanent::Permanent(char* _name, int sal)
	:Employee(_name)
{
	salary=sal;
}
int Permanent::GetPay()
{
	return salary;
}
/*****************Sales Person****************/
class Sales:public Permanent
{
private:
	int increase; //판매 수익
	double per;
public:
	Sales(char* _name, int sal,int increase);
	int GetIncentive();
	int GetPay();
};
Sales::Sales(char* _name, int _sal,int increase)
	:Permanent(_name,_sal)
{
	this->increase=increase;
}
int Sales::GetIncentive()
{
	per=0.15;
	return increase*per;
}
int Sales::GetPay()
{
	return Permanent::GetPay()+GetIncentive();
}
/*****************Temporary****************/
class Temporary:public Employee
{
private:
	int time;
	int pay;
public:
	Temporary(char* _name, int _time, int _pay);
	int GetPay();
};
Temporary::Temporary(char* _name, int _time, int _pay)
	:Employee(_name)
{
	time=_time;
	pay=_pay;
}
int Temporary::GetPay()
{
	return time*pay;
}
// control class
class Department
{
private:
	Employee* empList[10];
	int index;
public:
	Department(): index(0) {};
	void AddEmployee(Employee* emp);
	void ShowList(); //급여 리스트 출력
};
void Department::AddEmployee(Employee* emp)
{
	empList[index++]=emp;
}
void Department::ShowList() // 급여 리스트 출력
{
	for(int i=0; i<index; i++)
	{
		cout<<"name: "<< empList[i]->GetName()<<endl;
		cout<<"salary: "<<empList[i]->GetPay()<<endl;
	}
}

int main()
{
	Department department;

	department.AddEmployee(new Permanent("KIM",1000));
	department.AddEmployee(new Permanent("LEE",1500));
	department.AddEmployee(new Temporary("HAN",10,200));
	department.AddEmployee(new Temporary("JANG",12,300));
	department.AddEmployee(new Sales("KUM",1000,1000));
	department.AddEmployee(new Sales("SOL",1200,150));

	department.ShowList();
	return 0;
}









댓글