-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompany.h
182 lines (129 loc) · 3.18 KB
/
Company.h
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* Company.h
*
* 작성자: Jungdy
* 작성일자: 2017. 12. 28
* 주제명: 직원 명부 프로그램
*
*/
#ifndef _COMPANY_H_
#define _COMPANY_H_
#include "Emp.h"
#include "Node.h"
#include "LinkedList.h"
const int EXIT = 0;
const int INSERT = 1;
const int REMOVE = 2;
const int VIEW = 3;
template <typename T>
class Company{
private:
void insert(LinkedList<T>& linkedlist);
void remove(LinkedList<T>& linkedlist);
void view(LinkedList<T>& linkedlist);
public:
void run();
};
template <typename T>
void Company<T>::insert(LinkedList<T>& linkedlist){
Emp emp;
int id = 1;
char name[128];
int grade;
int pay;
cout << "이름을 입력하세요" << endl;
cin.clear();
cin.ignore();
cin.getline(name, sizeof(name));
cout << "직급을 입력하세요(숫자만)" << endl;
cin >> grade;
cout << "급여를 입력하세요(숫자만)" << endl;
cin >> pay;
emp.setId(id);
emp.setName(name);
emp.setGrade(grade);
emp.setPay(pay);
if ( !linkedlist.isEmpty() )
{
Node<Emp>* pNode = NULL;
pNode = linkedlist.peak();
Emp current = pNode->getData();
id = current.getId();
id++;
emp.setId(id);
}
linkedlist.push_back(emp);
}
template <typename T>
void Company<T>::remove(LinkedList<T>& linkedlist){
Emp emp;
if ( !linkedlist.isEmpty() ){
emp = linkedlist.pop();
cout << "---------------------------" << endl;
cout << "| 삭제 |" << endl;
cout << "---------------------------" << endl;
cout << "직원ID:" << emp.getId() << endl;
cout << "직원명:" << emp.getName() << endl;
cout << "직급:" << emp.getGrade() << endl;
cout << "급여:" << emp.getPay() << endl;
}
else
{
cout << "자료가 비어있습니다." << endl;
}
}
template <typename T>
void Company<T>::view(LinkedList<T>& linkedlist){
Emp emp;
if ( !linkedlist.isEmpty() ){
cout << "---------------------------" << endl;
cout << "| 조회 |" << endl;
cout << "---------------------------" << endl;
Node<Emp>* pNode = NULL;
pNode = linkedlist.atFirst();
while ( pNode != NULL ){
emp = pNode->getData();
cout << "직원ID:" << emp.getId() << endl;
cout << "직원명:" << emp.getName() << endl;
cout << "직급:" << emp.getGrade() << endl;
cout << "급여:" << emp.getPay() << endl;
pNode = pNode->getNext();
} // end of while
}
else
{
cout << "자료가 비어있습니다." << endl;
}
}
template <typename T>
void Company<T>::run(){
LinkedList<Emp> linkedlist;
int choose = -1;
while ( choose ){
cout << "------------------------------" << endl;
cout << "| Rabbit-white = 직원 명부 관리 |" << endl;
cout << "------------------------------" << endl;
cout << "1. 추가" << endl;
cout << "2. 삭제" << endl;
cout << "3. 조회" << endl;
cout << "0. 종료" << endl;
cin >> choose;
switch ( choose ){
// 추가
case INSERT:
insert(linkedlist);
break;
// 삭제
case REMOVE:
remove(linkedlist);
break;
case VIEW:
view(linkedlist);
break;
} // end of switch
// 조건:탈출
if ( choose == EXIT )
break;
} // end of while
}
#endif