/
상속2.cpp
140 lines (110 loc) · 3.73 KB
/
상속2.cpp
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
#include <iostream>
#include <string>
class Base {
public:
std::string parent_string;
Base() : parent_string("기반") {
std::cout << "기반 클래스" << std::endl;
}
void what(){
std::cout << parent_string << std::endl;
}
};
class Derived : private Base {
std::string child_string;
public:
Derived() : child_string("파생"), Base() {
std::cout << "파생 클래스" << std::endl;
}
void what() {
std::cout << child_string << std::endl;
}
};
class Employee {
protected:
std::string name;
int age;
std::string position;
int rank;
public:
Employee(std::string name, int age, std::string position, int rank)
: name(name), age(age), position(position), rank(rank) {}
Employee(const Employee& e) {
name = e.name;
age = e.age;
position = e.position;
rank = e.rank;
}
Employee() {}
void PrintInfo() {
std::cout << name << " (" << position << " , " << age << ") ==> "
<< CalculatePay() << std::endl;
}
int CalculatePay() { return 200 + rank * 50; }
};
class Manager : public Employee {
int year_of_service;
public:
Manager(std::string name, int age, std::string position, int rank, int year_of_service)
: Employee(name, age, position, rank),
year_of_service(year_of_service) {}
Manager(const Manager& manager) {
Employee(manager.name, manager.age, manager.position, manager.rank),
year_of_service = manager.year_of_service;
}
Manager() : Employee() {}
int CalculatePay() { return 200 + rank * 50 + 5 * year_of_service; }
void PrintInfo() {
std::cout << name << " (" << position << " , " << age << ", "
<< year_of_service << "년차) ==> " << CalculatePay() << "만원"
<< std::endl;
}
};
class EmployeeList {
int alloc_employee;
int current_employee;
int current_manager;
Employee** employee_list;
Manager** manager_list;
public:
EmployeeList(int allloc_employee) : alloc_employee(alloc_employee) {
employee_list = new Employee*[alloc_employee];
manager_list = new Manager*[alloc_employee];
current_employee = 0;
current_manager = 0;
}
void AddEmployee(Employee* employee) {
employee_list[current_employee] = employee;
current_employee++;
}
void AddManager(Manager* manager) {
manager_list[current_manager] = manager;
current_manager++;
}
int CureentEmployeeNum() { return current_employee + current_manager; }
void PrintEmployeeInfo() {
int total_pay = 0;
for (int i = 0; i < current_employee; i++) {
employee_list[i]->PrintInfo();
total_pay += employee_list[i]->CalculatePay();
}
for (int i = 0; i < current_manager; i++) {
manager_list[i]->PrintInfo();
total_pay += manager_list[i]->CalculatePay();
}
std::cout << "총 비용: " << total_pay << "만원" << std::endl;
}
~EmployeeList() {
for (int i = 0; i <current_employee; i++) {
delete employee_list[i];
}
for (int i = 0; i < current_manager; i++) {
delete manager_list[i];
}
delete[] employee_list;
delete[] manager_list;
}
};
int main() {
return 0;
}