1 #include <fstream> 2 #include <iomanip> 3 #include <conio.h> 4 #include <Windows.h> 5 #include <ctime> 6 #include "QuickSort.h" 7 using namespace std; 8 9 10 Node* Queue[100]; // 추가입력된데이터를저장하기위한 Queue 11 int QueueTop, QueueTail; 12 13 char password[5]={"1234"}; // 기본비밀번호 14 15 struct tm A; // 현재날짜를구하기위한변수 16 time_t t; 17 char today[10]; 18 19 void InitInput(){ 20 ifstream in("input.txt"); // input.txt에서처음데이터를읽어온다. 21 head->next = head->prev = NULL; 22 tail->next = tail->prev = NULL; 23 while(!in.eof()){ 24 Node* newnode = new Node; 25 in >> newnode->id >> newnode->name >> newnode->stock; 26 in >> newnode->indate >> newnode->outdate >> newnode->period; 27 in >> newnode->discusedate >> newnode->manager; 28 29 // 폐기현황 30 if(strcmp(newnode->discusedate,today) <= 0) newnode->condition[0]='o'; 31 else newnode->condition[0]='x'; 32 33 // 입고현황 34 if(strcmp(newnode->indate,today) <= 0) newnode->condition[1]='o'; 35 else newnode->condition[1]='x'; 36 37 // 출고현황 38 if(strcmp(newnode->outdate,today) <= 0) newnode->condition[2]='o'; 39 else newnode->condition[2]='x'; 40 41 newnode->condition[3] = NULL; 42 InsertNode(newnode); 43 } 44 } 45 void KeyInput(){ // 키보드로추가입력 46 Node* newnode = new Node; 47 cout << "ID를입력하세요 :";cin >> newnode->id; 48 cout << " 물품명 : " ; cin >> newnode->name; 49 cout << " 물품수량 : "; cin >> newnode->stock; 50 51 cout << " 입고일 : "; cin >> newnode->indate; 52 cout << " 출고일 : "; cin >> newnode->outdate; 53 cout << " 보관기간 : "; cin >> newnode->period; 54 55 cout << " 폐기일 : "; cin >> newnode->discusedate; 56 cout << " 관리자 : "; cin >> newnode->manager; 57 58 // 폐기현황 59 if(strcmp(newnode->discusedate,today) <= 0) newnode->condition[0]='o'; 60 else newnode->condition[0]='x'; 61 62 // 입고현황 63 if(strcmp(newnode->indate,today) <= 0) newnode->condition[1]='o'; 64 else newnode->condition[1]='x'; 1
65 66 // 출고현황 67 if(strcmp(newnode->outdate,today) <= 0) newnode->condition[2]='o'; 68 else newnode->condition[2]='x'; 69 70 Queue[QueueTail++] = newnode; // 추가입려된노드는 queue에저장 71 InsertNode(newnode); 72 } 73 void FileInput(){ // 파일로추가입력 74 char FileName[10]; 75 cout << " 입력받을파일의이름 : "; 76 cin >> FileName; // 확장자까지입력해야됨 77 ifstream in(filename); 78 while(!in.eof()){ 79 Node* newnode = new Node; 80 in >> newnode->id >> newnode->name >> newnode->stock; 81 in >> newnode->indate >> newnode->outdate >> newnode->period; 82 in >> newnode->discusedate >> newnode->manager; 83 84 // 폐기현황 85 if(strcmp(newnode->discusedate,today) <= 0) newnode->condition[0]='o'; 86 else newnode->condition[0]='x'; 87 88 // 입고현황 89 if(strcmp(newnode->indate,today) <= 0) newnode->condition[1]='o'; 90 else newnode->condition[1]='x'; 91 92 // 출고현황 93 if(strcmp(newnode->outdate,today) <= 0) newnode->condition[2]='o'; 94 else newnode->condition[2]='x'; 95 96 Queue[QueueTail++] = newnode; // 추가입력된데이터는큐에저장 97 InsertNode(newnode); 98 } 99 } 100 void Output(){ // 출력 101 Node* current = head->next; 102 cout << setw(10) << "ID" << setw(12) << " 물품명 " << setw(12) << " 재고현황 " << setw(12) << " 폐 기현황 " << setw(12) << " 입고현황 " << setw(12) << " 출고현황 " << endl; 103 cout << " ===========================================================================" << endl; 104 while(current!=tail){ 105 cout << setw(10) << current->id << setw(12) << current->name << setw(12) << current-> stock << setw(12) << current->condition[0] << setw(12) << current->condition[1] << setw(12) < < current->condition[2] << endl; 106 current = current->next; 107 } 108 } 109 void FileOutput(){ // 파일출력 110 char FileName[10]; 111 cout << " 출력할파일이름 : "; 112 cin >> FileName; 113 ofstream out(filename); 114 115 Node* current = head->next; 116 out << setw(10) << "ID" << setw(12) << " 물품명 " << setw(12) << " 재고현황 " << setw(12) << " 폐 기현황 " << setw(12) << " 입고현황 " << setw(12) << " 출고현황 " << endl; 117 out << " ===========================================================================" << endl ; 118 while(current!=tail){ 119 out << setw(10) << current->id << setw(12) << current->name << setw(12) << current->stock << setw(12) << current->condition[0] << setw(12) << current->condition[1] << setw(12) << current->condition[2] << endl; 120 current = current->next; 2
121 } 122 } 123 void Delete(){ 124 char id[10]; 125 cout << " 삭제하실물품 id : "; 126 cin >> id; 127 128 DeleteNode(id); 129 } 130 void InputMenu(){ 131 cout << "-------IntputMenu-------" << endl; 132 cout << " 1. 기본입력 " << endl; 133 cout << " 2. 추가입력 ( 키보드 )" << endl; 134 cout << " 3. 추가입력 ( 파일 )" << endl; 135 cout << " 4. 물품삭제 " << endl; 136 cout << " 0. 뒤로 " << endl; 137 cout << "------------------------" << endl; 138 cout << " 입력? "; 139 int choice; 140 cin >> choice; 141 switch(choice){ 142 case 1: 143 InitInput(); 144 break; 145 case 2: 146 KeyInput(); 147 break; 148 case 3: 149 FileInput(); 150 break; 151 case 4: 152 Delete(); 153 break; 154 case 0: 155 return; 156 default : 157 cout << " 입력오류 " << endl; 158 } 159 } 160 void OutputMenu(){ 161 cout << "-------OutputMenu-------" << endl; 162 cout << " 1. 모니터출력 " << endl; 163 cout << " 2. 파일출력 " << endl; 164 cout << " 0. 뒤로 " << endl; 165 cout << "------------------------" << endl; 166 cout << " 입력? "; 167 int choice; 168 cin >> choice; 169 switch(choice){ 170 case 1: 171 Output(); 172 break; 173 case 2: 174 FileOutput(); 175 break; 176 case 0: 177 return; 178 default : 179 cout << " 입력오류 " << endl; 180 } 181 } 182 void TotalOutput(){ 183 Node* current = head->next; 184 int cnt=0; 3
185 while(current!=tail){ 186 187 cout << " 물품명ID : " << current->id << endl; 188 cout << " 물품명 : " << current->name << endl; 189 cout << " 수량 : " << current->stock << endl; 190 cout << " 입고일 : " << current->indate << endl; 191 cout << " 출고일 : " << current->outdate << endl; 192 cout << " 보관기간 : " << current->period << endl; 193 cout << " 폐기일 : " << current->discusedate << endl; 194 cout << " 관리자 : " << current->manager << endl; 195 cout << "-----------------------------------" << endl; 196 current = current->next; 197 cnt++; 198 if(cnt%5==0) { 199 cout << " 아무키나입력해주세요."; 200 char temp = getch(); 201 cout << endl; 202 } 203 } 204 } 205 void ManageStock(){ // 재고관리하는함수 206 char InputId[10]; 207 cout << " 수정할물품명ID : "; 208 cin >> InputId; 209 Node* current = head->next; 210 while(current!=tail){ 211 if(strcmp(current->id, InputId) == 0){ 212 cout << " 수정할재고를입력해주세요 : "; 213 cin >> current->stock; 214 break; 215 } 216 current = current->next; 217 } 218 if(current == tail){ // 찾는 ID가없는경우에러메세지출력 219 cout << " 찾는물품명ID가없습니다." << endl; 220 } 221 } 222 void Manager(){ // 관리자함수 223 char input_pass[5]={0}; 224 cout << "-------Manager-------" << endl; 225 cout << " 비밀번호 : "; 226 for(int i=0;i<4;i++){ 227 input_pass[i]=getch(); 228 cout << "*"; 229 } 230 cout << endl; 231 if(strcmp(password,input_pass)!=0){ 232 cout << " 비밀번호가틀렸습니다." << endl; 233 return; 234 } 235 system("cls"); 236 cout << "-------Manager-------" << endl; 237 cout << " 1. 전체결과보기 " << endl; 238 cout << " 2. 물품재고관리 " << endl; 239 cout << " 3. 비밀번호변경하기 " << endl; 240 cout << " 0. 뒤로 " << endl; 241 cout << "---------------------" << endl; 242 cout << " 입력? " ; 243 int choice; 244 cin >> choice; 245 switch(choice){ 246 case 1: 247 TotalOutput(); 248 break; 4
249 case 2: 250 ManageStock(); 251 break; 252 case 3: 253 cout << " 바꾸실비밀번호 4자리를입력해주세요 : "; 254 cin >> password; 255 break; 256 default : 257 cout << " 입력오류 " << endl; 258 } 259 } 260 void Menu(){ // 기본메뉴 261 for(;;){ 262 cout << "-------Menu-------" << endl; 263 cout << " 1. 입력 " << endl; 264 cout << " 2. 출력 " << endl; 265 cout << " 3. 정렬 " << endl; 266 cout << " 4. 관리자 " << endl; 267 cout << " 0. 종료 " << endl; 268 cout << "-------------------" << endl; 269 cout << " 입력? " ; 270 int choice; 271 cin >> choice; 272 switch(choice){ 273 case 1: 274 InputMenu(); 275 break; 276 case 2: 277 OutputMenu(); 278 break; 279 case 3: 280 cout << " 1. ID 오름차순정렬 " << endl; 281 cout << " 2. ID 내림차순정렬 " << endl; 282 cout << " 3. 물품명오름차순정렬 " << endl; 283 cout << " 4. 물품명내림차순정렬 " << endl; 284 cout << " 5. 입고일오름차순정렬 " << endl; 285 cout << " 6. 입고일내림차순정렬 " << endl; 286 cout << " 입력?"; 287 cin >> choice; 288 if(choice>=1 && choice<=6) 289 QuickSort(choice,head->next,tail->prev); 290 else { 291 cout << " 입력오류 " << endl; 292 } 293 break; 294 case 4: 295 Manager(); 296 break; 297 case 0: 298 return; 299 default : 300 cout << " 입력오류 " << endl; 301 } 302 } 303 } 304 void main(){ 305 // 현재날짜구하기 306 time(&t); 307 localtime_s(&a,&t); 308 int year,month,day; 309 char temp[10]; 310 year = A.tm_year+1900; 311 month = A.tm_mon+1; 312 day = A.tm_mday; 5
313 itoa(year,temp,10); 314 strcat(today,temp); 315 316 strcat(today,"."); 317 318 if(month<10){ 319 strcat(today,"0"); 320 } 321 itoa(month,temp,10); 322 strcat(today,temp); 323 324 strcat(today,"."); 325 326 if(day<10){ 327 strcat(today,"0"); 328 } 329 itoa(day,temp,10); 330 strcat(today,temp); 331 332 333 Menu(); 334 } 335 6