首页 > 代码库 > 线性表应用之员工管理系统
线性表应用之员工管理系统
线性表的应用 ---- 员工管理系统。先码一下,方便以后回顾。
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 5 typedef struct Workers 6 { 7 char name[15]; //姓名 8 char department[18]; //单位 9 char gender[2]; //性别 10 unsigned int age; //年龄 11 unsigned long telephone; //电话 12 unsigned long wage; //工资 13 unsigned long num; //职工号 14 struct Workers *next; 15 }WNode,*WList; 16 17 18 int main() 19 { 20 int choose; 21 char jud[3]; 22 WList worker; 23 CreateInsertEmpInfo(&worker); 24 while(strcmp(jud,"no") != 0) 25 { 26 DispMenu(); 27 printf("请选择你要进行的操作:"); 28 scanf("%d",&choose); 29 switch(choose) 30 { 31 case 1:system("cls");InserEmpInfo(&worker);Judge(&jud);break; 32 case 2:system("cls");DeleteEmpInfo(&worker);Judge(&jud);break; 33 case 3:system("cls");DispEmpInfo(worker);Judge(&jud);break; 34 case 4:system("cls");AlterEmpInfo(&worker);Judge(&jud);break; 35 case 5:system("cls");SearchEmpInfo(worker);Judge(&jud);break; 36 case 6:system("cls");SortEmpInfo(worker);Judge(&jud);break; 37 case 7:system("cls");WageAverage(worker);Judge(&jud);break; 38 } 39 } 40 return 0; 41 } 42 43 44 /* 判断是否要继续操作*/ 45 void Judge(char *jud) 46 { 47 char choose[3]; 48 printf("请选择是否要继续操作?【yes/no】"); 49 scanf("%s",choose); 50 if(strcmp(choose,"yes") == 0) 51 { 52 strcpy(jud,choose); 53 }else if(strcmp(choose,"no") == 0) 54 { 55 exit(0); 56 }else 57 { 58 printf("输入错误,请重新输入!\n"); 59 Judge(&jud); 60 } 61 } 62 63 /* 系统界面*/ 64 void DispMenu() 65 { 66 printf("\t\t\t\t\t\t员工管理系统\n\n\n"); 67 printf("\t\t\t\t\t(1).增加员工信息\n"); 68 printf("\t\t\t\t\t(2).删除员工信息\n"); 69 printf("\t\t\t\t\t(3).显示员工信息\n"); 70 printf("\t\t\t\t\t(4).修改员工信息\n"); 71 printf("\t\t\t\t\t(5).查找员工信息\n"); 72 printf("\t\t\t\t\t(6).员工信息排序\n"); 73 printf("\t\t\t\t\t(7).员工平均工资\n"); 74 } 75 76 77 /* 创建存储员工信息链表*/ 78 void CreateInsertEmpInfo(WList *worker) 79 { 80 (*worker) = (WList)malloc(sizeof(WNode)); 81 (*worker)->next = NULL; 82 } 83 84 /* 插入员工信息*/ 85 void InserEmpInfo(WList *worker) 86 { 87 WList w; 88 WList p = (*worker); 89 while(p->next) 90 { 91 p = p->next; 92 } 93 w = (WList)malloc(sizeof(WNode)); 94 printf("请输入员工姓名:"); 95 scanf("%s",w->name); 96 printf("请输入员工单位:"); 97 scanf("%s",w->department); 98 printf("请输入员工性别:"); 99 scanf("%s",&w->gender); 100 printf("请输入员工年龄:"); 101 scanf("%d",&w->age); 102 printf("请输入员工电话:"); 103 scanf("%ld",&w->telephone); 104 printf("请输入员工工资:"); 105 scanf("%ld",&w->wage); 106 printf("请输入员工职工号:"); 107 scanf("%ld",&w->num); 108 w->next = NULL; 109 p->next = w; 110 printf("\n"); 111 } 112 113 /* 删除员工信息*/ 114 int DeleteEmpInfo(WList *worker) 115 { 116 unsigned long num; 117 WList w,p; 118 int flag = 0; 119 w = (*worker); 120 if(w->next == NULL) 121 { 122 printf("无任何员工信息!\n"); 123 return 0; 124 } 125 126 printf("请输入要删除的员工职工号:"); 127 scanf("%ld",&num); 128 while(w != NULL && w->next != NULL) 129 { 130 if(w->next->num == num) 131 { 132 flag = 1; 133 break; 134 } 135 w = w->next; 136 } 137 if(flag == 0) 138 { 139 printf("\n%ld该职工号不存在!\n",num); 140 } 141 else if(w != NULL) 142 { 143 p = w->next; 144 w->next = p->next; 145 free(p); 146 printf("职工号为 %ld 的员工信息删除成功!\n",num); 147 } 148 printf("\n"); 149 } 150 151 /* 修改员工信息*/ 152 int AlterEmpInfo(WList *worker) 153 { 154 WList w; 155 int flag = 0; 156 unsigned long num; 157 w = (*worker)->next; 158 if(w == NULL) 159 { 160 printf("无任何员工信息!\n"); 161 return 0; 162 } 163 164 printf("请输入要修改的员职工号:"); 165 scanf("%ld",&num); 166 while(w) 167 { 168 if(w->num == num) 169 { 170 flag = 1; 171 break; 172 } 173 w = w->next; 174 } 175 if(flag == 0) 176 { 177 printf("\n该职工号不存在!\n"); 178 } 179 else if(w != NULL) 180 { 181 AlterInfo(&w); 182 printf("职工号为 %ld 的员工信息修改成功!\n",num); 183 } 184 printf("\n"); 185 } 186 187 /* 修改员工信息具体操作*/ 188 void AlterInfo(WList *worker) 189 { 190 char name[15]; //姓名 191 char department[18]; //单位 192 char gender[2]; //性别 193 unsigned int age; //年龄 194 unsigned long telephone; //电话 195 unsigned long wage; //工资 196 unsigned long num; //职工号 197 198 char temp[18]; 199 printf("请输入你想要修改的员工信息[name/department/gender/age/telephone/wage/num]: "); 200 scanf("%s",temp); 201 202 if(strcmp(temp,"name") == 0){ 203 printf("请输入你要修改的信息:"); 204 scanf("%s",name); 205 strcpy((*worker)->name,name); 206 }else if(strcmp(temp,"department") == 0){ 207 printf("请输入你要修改的信息:"); 208 scanf("%s",department); 209 strcpy((*worker)->department,department); 210 }else if(strcmp(temp,"gender") == 0){ 211 printf("请输入你要修改的信息:"); 212 scanf("%s",gender); 213 strcpy((*worker)->gender,gender); 214 }else if(strcmp(temp,"age") == 0){ 215 printf("请输入你要修改的信息:"); 216 scanf("%d",&age); 217 (*worker)->age = age; 218 }else if(strcmp(temp,"telephone") == 0){ 219 printf("请输入你要修改的信息:"); 220 scanf("%ld",&telephone); 221 (*worker)->telephone = telephone; 222 }else if(strcmp(temp,"wage") == 0){ 223 printf("请输入你要修改的信息:"); 224 scanf("%ld",&wage); 225 (*worker)->wage = wage; 226 }else if(strcmp(temp,"num") == 0){ 227 printf("请输入你要修改的信息:"); 228 scanf("%ld",&num); 229 (*worker)->num = num; 230 }else{ 231 printf("输入错误,请重新输入!\n"); 232 AlterInfo(&worker); 233 } 234 } 235 236 /* 查找员工信息*/ 237 int SearchInfo(WList worker) 238 { 239 int choose; 240 printf("\t\t\t\t\t(1).按姓名查找\n"); 241 printf("\t\t\t\t\t(2).按职工号查找\n\n"); 242 printf("请输入你要选择的方式:"); 243 scanf("%d",&choose); 244 return choose; 245 } 246 247 248 /* 查找操作1*/ 249 void SearchOne(WList worker) 250 { 251 char name[15]; 252 int flag = 0; 253 WList w = worker->next; 254 printf("请输入你要查找的员工姓名:"); 255 scanf("%s",name); 256 while(w) 257 { 258 if(strcmp(w->name,name) == 0) 259 { 260 printf("员工姓名\t员工单位\t员工性别\t员工年龄\t员工电话\t员工工资\t员工职工号\n"); 261 printf("%8s\t%8s\t%8s\t%8d\t%8ld\t%8ld\t%10ld\n",w->name,w->department,w->gender,w->age,w->telephone,w->wage,w->num); 262 flag = 1; 263 } 264 w = w->next; 265 } 266 if(flag == 0) 267 { 268 printf("此员工不存在!\n"); 269 } 270 printf("\n"); 271 } 272 /* 查找操作2*/ 273 void SearchTwo(WList worker) 274 { 275 unsigned long num; 276 int flag = 0; 277 WList w = worker->next; 278 printf("请输入你要查找的员工职工号:"); 279 scanf("%ld",&num); 280 while(w) 281 { 282 if(w->num == num) 283 { 284 printf("员工姓名\t员工单位\t员工性别\t员工年龄\t员工电话\t员工工资\t员工职工号\n"); 285 printf("%8s\t%8s\t%8s\t%8d\t%8ld\t%8ld\t%10ld\n",w->name,w->department,w->gender,w->age,w->telephone,w->wage,w->num); 286 flag = 1; 287 break; 288 } 289 w = w->next; 290 } 291 if(flag == 0) 292 { 293 printf("此职工号不存在!\n"); 294 } 295 printf("\n"); 296 } 297 298 /* 查找员工信息的具体操作*/ 299 void SearchEmpInfo(WList worker) 300 { 301 WList w; 302 int choose; 303 choose = SearchInfo(worker); 304 switch(choose) 305 { 306 case 1:SearchOne(worker);break; 307 case 2:SearchTwo(worker);break; 308 } 309 310 } 311 312 /* 员工信息排序选择*/ 313 int SortInfo(WList worker) 314 { 315 int choose; 316 printf("\t\t\t\t\t(1).按姓名排序\n"); 317 printf("\t\t\t\t\t(2).按年龄排序\n"); 318 printf("\t\t\t\t\t(3).按工资排序\n"); 319 printf("\t\t\t\t\t(4).按职工号排序\n"); 320 printf("请输入你要选择的方式:"); 321 scanf("%d",&choose); 322 return choose; 323 } 324 325 /* 姓名排序*/ 326 void SortName(WList *worker) 327 { 328 int i,j,temp1; 329 char temp2[18]; 330 unsigned long temp3; 331 WList w,p; 332 for(w = (*worker)->next; w->next != NULL; w = w->next) 333 { 334 for(p = w->next ; p != NULL; p = p->next) 335 { 336 if(strcmp(w->name,p->name) > 0) 337 { 338 strcpy(temp2,w->name);strcpy(w->name,p->name);strcpy(p->name,temp2); 339 strcpy(temp2,w->department);strcpy(w->department,p->department);strcpy(p->department,temp2); 340 strcpy(temp2,w->gender);strcpy(w->gender,p->gender);strcpy(p->gender,temp2); 341 temp1=w->age;w->age=p->age;p->age=temp1; 342 temp3=w->telephone;w->telephone=p->telephone;p->telephone=temp3; 343 temp3=w->wage;w->wage=p->wage;p->wage=temp3; 344 temp3=w->num;w->num=p->num;p->num=temp3; 345 } 346 } 347 } 348 } 349 350 /* 年龄排序*/ 351 void SortAge(WList *worker) 352 { 353 int i,j,temp1; 354 char temp2[18]; 355 unsigned long temp3; 356 WList w,p; 357 for(w = (*worker)->next; w->next != NULL; w = w->next) 358 { 359 for(p = w->next ; p != NULL; p = p->next) 360 { 361 if(w->age > p->age) 362 { 363 strcpy(temp2,w->name);strcpy(w->name,p->name);strcpy(p->name,temp2); 364 strcpy(temp2,w->department);strcpy(w->department,p->department);strcpy(p->department,temp2); 365 strcpy(temp2,w->gender);strcpy(w->gender,p->gender);strcpy(p->gender,temp2); 366 temp1=w->age;w->age=p->age;p->age=temp1; 367 temp3=w->telephone;w->telephone=p->telephone;p->telephone=temp3; 368 temp3=w->wage;w->wage=p->wage;p->wage=temp3; 369 temp3=w->num;w->num=p->num;p->num=temp3; 370 } 371 } 372 } 373 } 374 /* 工资排序*/ 375 void SortWage(WList *worker) 376 { 377 int i,j,temp1; 378 char temp2[18]; 379 unsigned long temp3; 380 WList w,p; 381 for(w = (*worker)->next; w->next != NULL; w = w->next) 382 { 383 for(p = w->next ; p != NULL; p = p->next) 384 { 385 if(w->wage > p->wage) 386 { 387 strcpy(temp2,w->name);strcpy(w->name,p->name);strcpy(p->name,temp2); 388 strcpy(temp2,w->department);strcpy(w->department,p->department);strcpy(p->department,temp2); 389 strcpy(temp2,w->gender);strcpy(w->gender,p->gender);strcpy(p->gender,temp2); 390 temp1=w->age;w->age=p->age;p->age=temp1; 391 temp3=w->telephone;w->telephone=p->telephone;p->telephone=temp3; 392 temp3=w->wage;w->wage=p->wage;p->wage=temp3; 393 temp3=w->num;w->num=p->num;p->num=temp3; 394 } 395 } 396 } 397 } 398 /* 职工号排序*/ 399 void SortNum(WList *worker) 400 { 401 int i,j,temp1; 402 char temp2[18]; 403 unsigned long temp3; 404 WList w,p; 405 for(w = (*worker)->next; w->next != NULL; w = w->next) 406 { 407 for(p = w->next ; p != NULL; p = p->next) 408 { 409 if(w->num > p->num) 410 { 411 strcpy(temp2,w->name);strcpy(w->name,p->name);strcpy(p->name,temp2); 412 strcpy(temp2,w->department);strcpy(w->department,p->department);strcpy(p->department,temp2); 413 strcpy(temp2,w->gender);strcpy(w->gender,p->gender);strcpy(p->gender,temp2); 414 temp1=w->age;w->age=p->age;p->age=temp1; 415 temp3=w->telephone;w->telephone=p->telephone;p->telephone=temp3; 416 temp3=w->wage;w->wage=p->wage;p->wage=temp3; 417 temp3=w->num;w->num=p->num;p->num=temp3; 418 } 419 } 420 } 421 } 422 423 /* 员工信息排序*/ 424 void SortEmpInfo(WList worker) 425 { 426 WList w; 427 int choose; 428 choose = SortInfo(worker); 429 switch(choose) 430 { 431 case 1:SortName(&worker);break; 432 case 2:SortAge(&worker);break; 433 case 3:SortWage(&worker);break; 434 case 4:SortNum(&worker);break; 435 } 436 } 437 438 /* 显示员工信息*/ 439 void DispEmpInfo(WList worker) 440 { 441 WList w = worker->next; 442 if(w) 443 { 444 while(w) 445 { 446 printf("员工姓名\t员工单位\t员工性别\t员工年龄\t员工电话\t员工工资\t员工职工号\n"); 447 printf("%8s\t%8s\t%8s\t%8d\t%8ld\t%8ld\t%10ld\n",w->name,w->department,w->gender,w->age,w->telephone,w->wage,w->num); 448 w = w->next; 449 } 450 }else 451 { 452 printf("无任何员工信息!\n"); 453 } 454 printf("\n"); 455 } 456 457 /* 显示员工工资,并输出平均工资*/ 458 void WageAverage(WList worker) 459 { 460 double sumWage = 0; 461 int number = 0; 462 WList w = worker->next; 463 if(w) 464 { 465 while(w) 466 { 467 printf("员工姓名\t员工工资\t员工职工号\n"); 468 printf("%8s\t%8ld\t%10ld\n",w->name,w->wage,w->num); 469 sumWage += w->wage; 470 number++; 471 w = w->next; 472 } 473 printf("\n平均工资为:%.2lf",sumWage / number); 474 }else 475 { 476 printf("无任何员工信息!\n"); 477 } 478 printf("\n"); 479 }
线性表应用之员工管理系统
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。