项目 C++ C++练习项目 小楼夜听雨 2024-05-09 2025-01-04 基于数组的通讯录管理系统 需要实现以下功能 1.添加联系人 向通讯录中添加新人,信息包括(姓名,性别,年龄,联系电话,家庭住址)最多记录1000人 2.显示联系人 显示通讯录中所有人的信息 3.删除联系人 按照姓名进行删除指定联系人 4.查找联系人 按照姓名查找指定联系人信息 5.修改联系人 按照姓名重新修改指定联系人 6.清空联系人 清空通讯录中所有信息 7.退出通讯录 退出当前使用的通讯录
我的: 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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 #include <iostream> #include <string> using namespace std;struct contact ;int DH (contact contactarr[]) ;void caidang (int * getfunction) ;void caidang (int * getfunction) { cout << endl<<endl << "*******************\n" << "********菜单*******\n" << "* 1.添加联系人 *\n" << "* 2.显示联系人 *\n" << "* 3.删除联系人 *\n" << "* 4.查找联系人 *\n" << "* 5.修改联系人 *\n" << "* 6.清空联系人 *\n" << "* 7.退出通讯录 *\n" << "*******************\n" << endl; cout << "请输入想要使用的功能" << endl; cin >> *getfunction; } struct contact { string name; string sex; int age; int telephone; string homeAddress; };void AddContact (contact contactarr[], int len) { int a=DH (contactarr); cout << "姓名:" << endl; string tampName; cin >> tampName; contactarr[a].name = tampName; cout << "性别:" << endl; string tampSex; cin >> tampSex; contactarr[a].sex = tampSex; cout << "年龄:" << endl; int tampAge; cin >> tampAge; contactarr[a].age = tampAge; cout << "电话:" << endl; int tamptelephone; cin >> tamptelephone; contactarr[a].telephone= tamptelephone; cout << "地址:" << endl; string tampHome; cin >> tampHome; contactarr[a].homeAddress= tampHome; cout << "输入成功" << endl; cout << "姓名:" << contactarr[a].name << "性别:" << contactarr[a].sex << "年龄:" << contactarr[a].age << "联系电话:" << contactarr[a].telephone << "家庭住址:" << contactarr[a].homeAddress << endl; }; void ShouContact (contact contactarr[], int len) { for (int b = 0 ; b < 1000 ; b++) { if (contactarr[b].telephone != 0 ) { cout << "姓名:" << contactarr[b].name << "性别:" << contactarr[b].sex << "年龄:" << contactarr[b].age << "联系电话:" << contactarr[b].telephone << "家庭住址:" << contactarr[b].homeAddress << endl; } } } void DeleteContact (contact contactarr[], int len) { int c = 0 ; cout << "请输入想要删除的联系人的名字:" << endl; string name; cin >> name; for (int b = 0 ; b < 1000 ; b++) { if (contactarr[b].name==name) { contactarr[b].name = "0" ; contactarr[b].sex = "0" ; contactarr[b].age = 0 ; contactarr[b].telephone = 0 ; contactarr[b].homeAddress = "0" ; cout << "删除成功" << endl; c = 1 ; } } if (c == 0 ) { cout << "查无此人" << endl; } } void FindContact (contact contactarr[], int len) { int c = 0 ; cout << "请输入想要查找的联系人的名字:" << endl; string name; cin >> name; for (int b = 0 ; b < 1000 ; b++) { if (contactarr[b].name == name) { cout << "姓名:" << contactarr[b].name << "性别:" << contactarr[b].sex << "年龄:" << contactarr[b].age << "联系电话:" << contactarr[b].telephone << "家庭住址:" << contactarr[b].homeAddress << endl; cout << "查询成功" << endl; c = 1 ; } } if (c == 0 ) { cout << "查无此人" << endl; } } void ModifyContact (contact contactarr[], int len) { int c = 0 ; cout << "请输入想要修改的联系人的名字:" << endl; string name1; cin >> name1; for (int b = 0 ; b < 1000 ; b++) { if (contactarr[b].name == name1) { cout << "姓名:" << contactarr[b].name << "性别:" << contactarr[b].sex << "年龄:" << contactarr[b].age << "联系电话:" << contactarr[b].telephone << "家庭住址:" << contactarr[b].homeAddress << endl; cout << "查询成功" << endl; c = 1 ; cout << "请输入你想修改的信息" << endl; cout << "1.姓名" << endl; cout << "2.性别" << endl; cout << "3.年龄" << endl; cout << "4.电话" << endl; cout << "5.地址" << endl; int a = 0 ; string temp_1; int temp_2; cin >> a; switch (a) { case 1 :cout << "请输入新的姓名" << endl; cin >> temp_1; contactarr[b].name = temp_1; break ; case 2 :cout << "请输入新的性别" << endl; cin >> temp_1; contactarr[b].sex = temp_1; break ; case 3 :cout << "请输入新的年龄" << endl; cin >> temp_2; contactarr[b].age = temp_2; break ; case 4 :cout << "请输入新的电话" << endl; cin >> temp_2; contactarr[b].telephone = temp_2; break ; case 5 :cout << "请输入新的地址" << endl; cin >> temp_1; contactarr[b].homeAddress = temp_1; break ; } cout << "修改成功" << endl;break ; } } if (c == 0 ) { cout << "查无此人" << endl; } } int DH (contact contactarr[]) { int a = 0 ; for (int b = 0 ; b < 1000 ; b++) { if (contactarr[b].telephone == 0 ) { a = b; break ; } } return a; } void ClearContact (contact contactarr[], int len) { for (int b = 0 ; b < 1000 ; b++) { contactarr[b].name = "0" ; contactarr[b].sex = "0" ; contactarr[b].age = 0 ; contactarr[b].telephone = 0 ; contactarr[b].homeAddress = "0" ; } cout << "清空成功" << endl; } int main () { contact contactarr[1000 ]{}; int len = sizeof (contactarr) / sizeof (contactarr[0 ]); int a = 0 ; int getfunction; ABC: caidang (&getfunction); switch (getfunction) { case 1 :AddContact (contactarr, len);goto ABC;break ; case 2 :ShouContact (contactarr, len); goto ABC; break ; case 3 :DeleteContact (contactarr, len); goto ABC; break ; case 4 :FindContact (contactarr, len); goto ABC; break ; case 5 :ModifyContact (contactarr, len); goto ABC; break ; case 6 :ClearContact (contactarr, len); goto ABC; break ; case 7 :cout<<"欢迎下次使用" <<endl;system ("pause" ); default :break ; } return 0 ; }
教程的: 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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 #include <iostream> #include <string> using namespace std;#define MAX 1000 struct person { string name; int sex; int age; string telephone; string homeAddress; };struct Addressbooks { person personArray[MAX]{}; int m_Size = 0 ; }; void addperson (Addressbooks*abs) { string name; if (abs->m_Size==MAX) { cout << "通讯录已满,无法添加" << endl; return ; } else { cout << "姓名:" << endl; cin >> name; abs->personArray[abs->m_Size].name = name; cout << "性别:" << endl; cout << "1.男" << endl; cout << "2.女" << endl; int sex = 0 ; while (true ) { cin >> sex; if (sex == 1 ||sex==2 ) { abs->personArray[abs->m_Size].sex = sex; break ; } cout << "错误" << endl; } cout << "年龄:" << endl; int agx = 0 ; cin >> agx; abs->personArray[abs->m_Size].age = agx; cout << "电话:" << endl; string phone; cin >> phone; abs->personArray[abs->m_Size].telephone = phone; cout << "地址:" << endl; string address; cin >> address; abs->personArray[abs->m_Size].homeAddress = address; abs->m_Size++; system ("pause" ); system ("cls" ); } } void showperson (Addressbooks* abs) { if (abs->m_Size == 0 ) { cout << "当前联系人为空" <<endl; } else { for (int i = 0 ; i<abs->m_Size;i++) { cout << "姓名:" << abs->personArray[i].name<<"\t" << "性别:" << (abs->personArray[i].sex==1 ?"男" :"女" ) << "\t" << "年龄:" << abs->personArray[i].age << "\t" << "联系电话:" << abs->personArray[i].telephone << "\t" << "家庭住址:" << abs->personArray[i].homeAddress << endl; } } system ("pause" ); system ("cls" ); } int isExist (Addressbooks* abs, string a) { for (int i = 0 ; i < abs->m_Size; i++) { if (abs->personArray[i].name == a) { return i; } } return -1 ; } void deletePerson (Addressbooks* abs) { cout << "请输入想要删除的联系人的名字:" << endl; string name; cin >> name; int a = isExist (abs, name); if (a != -1 ) { for (; abs->m_Size >a ; a++) { abs->personArray[a + 1 ] = abs->personArray[a]; } abs->m_Size--; cout << "删除成功" << endl; } else cout << "查无此人" << endl; system ("pause" ); system ("cls" ); } void FindContact (Addressbooks*abs) { cout << "请输入想要查找的联系人的名字:" << endl; string name; cin >> name; int a = isExist (abs, name); if (a!=-1 ) { cout << "姓名:" << abs->personArray[a].name << "\t" << "性别:" << (abs->personArray[a].sex == 1 ? "男" : "女" ) << "\t" << "年龄:" << abs->personArray[a].age << "\t" << "联系电话:" << abs->personArray[a].telephone << "\t" << "家庭住址:" << abs->personArray[a].homeAddress << endl; } else { cout << "查无此人" << endl; } system ("pause" ); system ("cls" ); } void ModifyContact (Addressbooks* abs) { cout << "请输入想要修改的联系人的名字:" << endl; string name1; cin >> name1; int a = isExist (abs, name1); if (a != -1 ) { string temp_1; int temp_2; cout << "请输入新的姓名" << endl; cin >> temp_1; abs->personArray[a].name = temp_1; cout << "请输入新的性别" << endl; int sex = 0 ; while (true ) { cin >> sex; if (sex == 1 || sex == 2 ) { abs->personArray[a].sex = sex; break ; } cout << "错误" << endl; } cout << "请输入新的年龄" << endl; cin >> temp_2; abs->personArray[a].age = temp_2; cout << "请输入新的电话" << endl; cin >> temp_2; abs->personArray[a].telephone = temp_2; cout << "请输入新的地址" << endl; cin >> temp_1; abs->personArray[a].homeAddress = temp_1; cout << "修改成功" << endl; } else { cout << "查无此人" << endl; } system ("pause" ); system ("cls" ); } void cleanPerson (Addressbooks* abs) { abs->m_Size = 0 ; cout << "通讯录已经清空" << endl; system ("pause" ); system ("cls" ); } void caidang () { cout << endl << endl << "*******************\n" << "********菜单*******\n" << "* 1.添加联系人 *\n" << "* 2.显示联系人 *\n" << "* 3.删除联系人 *\n" << "* 4.查找联系人 *\n" << "* 5.修改联系人 *\n" << "* 6.清空联系人 *\n" << "* 7.退出通讯录 *\n" << "*******************\n" << endl; } int main () { Addressbooks abs; int select = 0 ; while (true ) { caidang (); cin >> select; switch (select) { case 1 :addperson (&abs); break ; case 2 :showperson (&abs); break ; case 3 :deletePerson (&abs); break ; case 4 :FindContact (&abs); break ; case 5 :ModifyContact (&abs); break ; case 6 :cleanPerson (&abs); break ; case 7 :cout << "欢迎下次使用" << endl; system ("pause" ); return 0 ; break ; default :break ; } } }
不同之处: 教程
定义一个联系人结构体数组
通讯录中记录当前联系人个数
我用goto语句
教程用while(true)循环
基于类和对象的职工管理系统 职工管理系统可以用来管理公司内所有员工的信息
公司中职工分为三类:普通员工,经理,老板显示信息时,需要显示职工编号,姓名,部门,职责
普通员工职责:完成经理交给的任务
经理职责:完成老板交给的任务,并下发任务给员工
老板职责:管理公司所有事物
管理系统需要实现以下功能
退出管理程序:退出当前管理程序
增加职工信息:实现批量添加职工功能,将信息入录文件,职工信息为:职工编号,姓名,部门
显示职工信息:显示公司内所有职工信息
删除离职职工:按照编号删除指定的职工
修改职工信息:按照编号修改职工个人信息
查找职工信息:按照职工的编号或者姓名查找相关人员信息
按照编号排序:按照编号进行排序,排序规则由用户指定
清空所有文档:清空文件中记录的所有职工的信息(清空前需要再次确认,防止误删)
头文件 职工.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #pragma once #include <iostream> #include <string> using namespace std;class Worker { public : virtual void showinfo () = 0 ; virtual string getgwnamae () = 0 ; int m_ON; string m_name; int m_department; };
普通员工.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #pragma once #include <iostream> #include <string> #include "职工类.h" using namespace std;class Employee :public Worker{ public : Employee (int ON, string name, int did); void showinfo () ; string getgwnamae () ; };
老板.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #pragma once #include <iostream> #include <string> #include "职工类.h" using namespace std;class boss :public Worker{ public : boss (int ON, string name, int did); void showinfo () ; string getgwnamae () ; };
经理.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #pragma once #include <iostream> #include <string> #include "职工类.h" using namespace std;class manager :public Worker{ public : manager (int ON, string name, int did); void showinfo () ; string getgwnamae () ; };
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 #pragma once #include <iostream> #include "职工类.h" #include "普通员工.h" #include "经理.h" #include "老板.h" #include <fstream> #define FIL "emp.txt" using namespace std;class WorderManager { public : void menu () ; void out () ; int m_worker_mun; Worker** m_arr; void add () ; void save () ; int SSD () ; bool PD; void init_Emp () ; void see () ; void XXD () ; int CPDD (int id) ; void mod () ; void XXDD () ; void paixu () ; void BB () ; WorderManager (); ~WorderManager (); };
源文件 普通员工
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #include "普通员工.h" Employee:: Employee (int ON, string name, int did) { m_ON = ON; m_name = name; m_department = did; } ; void Employee::showinfo () { cout << "编号:" << m_ON << "\t\t姓名:" << m_name << "\t\t岗位:" << getgwnamae () << "\t\t岗位职责:完成经理交给的任务" << endl; }; string Employee::getgwnamae () { return "员工" ; };
老板
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #include "老板.h" boss::boss (int ON, string name, int did) { m_ON = ON; m_name = name; m_department = did; } ; void boss::showinfo () { cout << "编号:" << m_ON << "\t\t姓名:" << m_name << "\t\t岗位:" << getgwnamae () << "\t\t岗位职责:管理公司所有事物" << endl; }; string boss::getgwnamae () { return "老板" ; };
经理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #include "经理.h" manager::manager (int ON, string name, int did) { m_ON = ON; m_name = name; m_department = did; } ; void manager::showinfo () { cout << "编号:" << m_ON << "\t\t姓名:" << m_name << "\t\t岗位:" << getgwnamae () << "\t\t岗位职责:完成老板交给的任务并并下发任务给员工" << endl; }; string manager::getgwnamae () { return "经理" ; };
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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 #include "管理.h" WorderManager::WorderManager () { ifstream ifs; ifs.open (FIL, ios::in); if (!ifs.is_open ()) { m_worker_mun = 0 ; m_arr = NULL ; this ->PD = true ; ifs.close (); return ; } char A; ifs >> A; if (ifs.eof ()) { m_worker_mun = 0 ; m_arr = NULL ; this ->PD = true ; ifs.close (); return ; } int num; num = SSD (); this ->m_worker_mun = num; m_arr = new Worker * [m_worker_mun]; init_Emp (); this ->PD = false ; ifs.close (); return ; }; WorderManager::~WorderManager () { if (this ->m_arr != NULL ) { delete [] this ->m_arr; this ->m_arr = NULL ; } }; void WorderManager::menu () { cout << "**********************" << endl; cout << "*欢迎使用职工管理系统*" << endl; cout << "*1.增加职工信息 *" << endl; cout << "*2.显示职工信息 *" << endl; cout << "*3.删除离职职工 *" << endl; cout << "*4.修改职工信息 *" << endl; cout << "*5.查找职工信息 *" << endl; cout << "*6.排序职工信息 *" << endl; cout << "*7.清空所有文档 *" << endl; cout << "*8.退出管理程序 *" << endl; cout << "**********************" << endl; }; void WorderManager::out () { cout << "欢迎下次使用" << endl; system ("pause" ); exit (0 ); }; void WorderManager::add () { cout << "请输入人数:" << endl; int number; cin >> number; int wordernum = m_worker_mun + number; if (number > 0 ) { Worker** m_wor1 = new Worker * [wordernum]; if (m_worker_mun != 0 ) { for (int a = 0 ; a < m_worker_mun; a++) { m_wor1[a] = m_arr[a]; } } for (int a = 0 ; a < number; a++) { cout << "请输入编号:" << endl; int on; cin >> on; cout << "请输入姓名:" << endl; string name; cin >> name; cout << "请输入部门:" << endl; cout << "1.老板:" << endl; cout << "2.经理:" << endl; cout << "3.普通员工:" << endl; int department; Worker* worker = NULL ; while (true ) { cin >> department; switch (department) { case 1 : { worker = new boss (on, name, department); break ; } case 2 : { worker = new manager (on, name, department); break ; } case 3 : { worker = new Employee (on, name, department); break ; } default : {cout << "没有这个岗位,请重新输入" << endl; } } if (department == 1 || department == 2 || department == 3 ) { cout << "添加成功" << endl; m_wor1[this ->m_worker_mun + a] = worker; break ; } } system ("pause" ); system ("cls" ); } m_worker_mun = wordernum; this ->PD = false ; delete []this ->m_arr; this ->m_arr = m_wor1; save (); } else { cout << "错误" << endl; } } void WorderManager::save () { ofstream ofs; ofs.open (FIL, ios::out); for (int a = 0 ; a < this ->m_worker_mun; a++) { ofs << this ->m_arr[a]->m_ON<< " " << this ->m_arr[a]->m_name << " " << this ->m_arr[a]->m_department << " " ; } ofs.close (); } int WorderManager::SSD () { ifstream ifs; ifs.open (FIL, ios::in); int on, id; string name; int RS = 0 ; while (ifs >> on && ifs >> name && ifs >> id) { RS++; } ifs.close (); return RS; } void WorderManager::init_Emp () { ifstream ifs; ifs.open (FIL, ios::in); int on, id; string name; int a = 0 ; while (ifs >> on && ifs >> name && ifs >> id) { Worker* worker1 = NULL ; if (id == 1 ) { worker1 = new boss (on, name, id); } else if (id == 2 ) { worker1 = new manager (on, name, id); } else { worker1 = new Employee (on, name, id); } m_arr[a] = worker1; a++; } ifs.close (); } void WorderManager::see () { if (this ->PD) { cout << "文件不存在或者记录为空" << endl; } else { for (int a = 0 ; a < this ->m_worker_mun; a++) { m_arr[a]->showinfo (); } } system ("pause" ); system ("cls" ); } int WorderManager::CPDD (int id) { int X = -1 ; for (int i = 0 ; i < this ->m_worker_mun; i++) { if (id == this ->m_arr[i]->m_ON) { X = i; break ; } } return X; } void WorderManager::XXD () { int a; cout << "请输入想删除的员工编号" << endl; cin >> a; int s = CPDD (a); if (s != -1 ) { for (int i = s; i < this ->m_worker_mun - 1 ; i++) { this ->m_arr[i] = this ->m_arr[i + 1 ]; } this ->m_worker_mun--; this ->save (); cout << "删除成功" << endl; if (this ->m_worker_mun == 0 ) { this ->PD = true ; } system ("pause" ); system ("cls" ); } else { cout << "员工不存在" << endl; system ("pause" ); system ("cls" ); } } void WorderManager::mod () { int a; cout << "请输入想修改的员工编号" << endl; cin >> a; int s = CPDD (a); if (s != -1 ) { cout << "请输入编号:" << endl; int on; cin >> on; cout << "请输入姓名:" << endl; string name; cin >> name; cout << "请输入部门:" << endl; cout << "1.老板:" << endl; cout << "2.经理:" << endl; cout << "3.普通员工:" << endl; int department; Worker* worker = NULL ; while (true ) { cin >> department; switch (department) { case 1 : { worker = new boss (on, name, department); break ; } case 2 : { worker = new manager (on, name, department); break ; } case 3 : { worker = new Employee (on, name, department); break ; } default : {cout << "没有这个岗位,请重新输入" << endl; } } if (department == 1 || department == 2 || department == 3 ) { delete this ->m_arr[s]; this ->m_arr[s] = worker; break ; } } this ->save (); cout << "修改成功" << endl; system ("pause" ); system ("cls" ); } else { cout << "员工不存在" << endl; } } void WorderManager::XXDD () { cout << "查找方式:" << endl; cout << "1.编号查找" << endl; cout << "2.姓名查找" << endl; while (true ) { int c; cin >> c; if (c == 1 ) { int a; cout << "请输入想查找的员工编号" << endl; cin >> a; int s = CPDD (a); if (s != -1 ) { this ->m_arr[s]->showinfo (); } else { cout << "员工不存在" << endl; } break ; } else if (c == 2 ) { bool ccc = false ; cout << "请输入想查找的员工姓名" << endl; string d; cin >> d; for (int i = 0 ; i < this ->m_worker_mun; i++) { if (this ->m_arr[i]->m_name == d) { this ->m_arr[i]->showinfo (); ccc = true ; } } if (ccc == true ) { cout << "查询成功" << endl; } else { cout << "查无此人" << endl; } break ; } else { cout << "请重新输入" << endl; } } system ("pause" ); system ("cls" ); } void WorderManager::paixu () { cout << "请选择排序类型" << endl; cout << "1.升序" << endl; cout << "2.降序" << endl; int a; while (true ) { Worker* w1 = NULL ; cin >> a; if (a == 1 ) { for (int i = 0 ; i < this ->m_worker_mun - 1 ; i++) { for (int b = 0 ; b < this ->m_worker_mun - i - 1 ; b++) { if (this ->m_arr[b]->m_ON > this ->m_arr[b + 1 ]->m_ON) { w1 = this ->m_arr[b]; this ->m_arr[b] = this ->m_arr[b + 1 ]; this ->m_arr[b + 1 ] = w1; } } } this ->save (); break ; } else if (a == 2 ) { for (int i = 0 ; i < this ->m_worker_mun - 1 ; i++) { for (int b = 0 ; b < this ->m_worker_mun - i - 1 ; b++) { if (this ->m_arr[b]->m_ON < this ->m_arr[b + 1 ]->m_ON) { w1 = this ->m_arr[b]; this ->m_arr[b] = this ->m_arr[b + 1 ]; this ->m_arr[b + 1 ] = w1; } } } this ->save (); break ; } else { cout << "错误,请重新输入" << endl; } } } void WorderManager::BB () { cout << "此选项将会清空数据,请输入 1 再次确认" << endl; int a = 0 ; cin >> a; if (a == 1 ) { ofstream ofs; ofs.open (FIL, ios::trunc); if (this ->m_arr != NULL ) { for (int a = 0 ; a < this ->m_worker_mun; a++) { if (this ->m_arr[a] != NULL ) { delete this ->m_arr[a]; this ->m_arr[a] = NULL ; } } } this ->m_arr = NULL ; this ->m_worker_mun = 0 ; this ->PD = true ; } else { cout << "清空操作已取消" << endl; } system ("pause" ); system ("cls" ); }
职工管理系统(启动项 )
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 #include <iostream> #include "管理.h" using namespace std;#include "职工类.h" #include "普通员工.h" #include "经理.h" #include "老板.h" int main () { WorderManager mn; int a; while (true ) { mn.menu (); cout << "请选择想要的功能" << endl; cin >> a; switch (a) { case 1 :mn.add (); break ; case 2 :mn.see (); break ; case 3 :mn.XXD (); break ; case 4 :mn.mod (); break ; case 5 :mn.XXDD (); break ; case 6 :mn.paixu (); break ; case 7 :mn.BB (); break ; case 8 : mn.out (); break ; default : system ("cls" ); break ; } system ("cls" ); } system ("pause" ); return 0 ; }