C언어

c++ 공부 요점정리 17

뮹실이 2013. 11. 27. 21:47







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
// =====================================================
// 32 상속으로 들어가기에 앞서서
// =====================================================
//
// 
//
#include <iostream>
using std::endl;
using std::cout;

// entity 클래스(데이터)
class Permanent
{
private:
	char name[20];	
	int salary;
public:
	Permanent(char* _name, int sal);
	const char* GetName();
	int GetPay();
};

Permanent::Permanent(char* _name, int sal) {
	strcpy(name, _name);
	salary=sal;
}
const char* Permanent::GetName()
{
	return name;
}	
int Permanent::GetPay()
{
	return salary;
}

// 컨트롤 클래스
class Department
{
private:
	Permanent* empList[10];
	int index;
public:
	Department(): index(0) { };
	void AddEmployee(Permanent* emp);
	void ShowList();
};

void Department::AddEmployee(Permanent* 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;
}