2013. 12. 4. 00:27 C언어

c++ 공부 요점정리 23







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
// ##########################################
//
// 40 Employee Problem 해결
//
// ##########################################
#include <iostream>
using std::endl;
using std::cout;

class Employee
{
protected:
	char name[20];
public:
	Employee(char* _name){
		strcpy(name, _name);
	}	
	const char* GetName();
};
const char* Employee::GetName()
{
	return name;
}	

class Permanent : public Employee
{
private:
	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;
}

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;
		cout<<endl;
	}
}

int main()
{
	//직원을 관리하는 CONTROL 클래스
	Department department;

	//직원 등록.
	department.AddEmployee(new Permanent("KIM", 1000));
	department.AddEmployee(new Permanent("LEE", 1500));
	department.AddEmployee(new Permanent("JUN", 2000));

	//최종적으로 이번달에 지불해야할 급여는?
	department.ShowList();	
	return 0;
}








'C언어' 카테고리의 다른 글

c++ 공부 요점정리 25  (0) 2013.12.05
c++ 공부 요점정리 24  (0) 2013.12.04
c++ 공부 요점정리 22  (0) 2013.12.04
c++ 공부 요점정리 21  (0) 2013.11.28
c++ 공부 요점정리 20  (0) 2013.11.27
Posted by 뮹실이

최근에 달린 댓글

05-22 07:01
Yesterday
Today
Total