1 #include"stdio.h" 2 #include"string.h" 3 #define MAX 120 4 #include "malloc.h" 5 #include "stdlib.h" 6 #define x 23 7 #define y 22 8 typedef struct 9 { 10 int sid;//学号 11 char Name[10];//姓名 12 char Class[20];//班级 13 int Age;//年龄 14 char Sex;//性别 15 int floor; 16 int rid;//宿舍号 17 }Student; 18 typedef struct 19 { 20 int rid;//宿舍号 21 int Bedspace;//床位 22 int The_table;//桌子 23 int Stool;//凳子 24 int Fan;//风扇 25 int Lamp;//灯 26 }Room;//房间 27 28 typedef struct 29 { 30 Student Data[MAX]; 31 Room data[5][31]; 32 int Last;//记录Data当前的位置 33 34 }SeqList; 35 SeqList *Int_Room() 36 { //初始化 37 SeqList *SL ; 38 int i,j; 39 SL = (SeqList *) malloc (sizeof(SeqList)); 40 for(i=1;i<5;i++) 41 for(j=1;j<31;j++) 42 { 43 SL->data[i][j].Bedspace=4; 44 SL->data[i][j].Fan=2; 45 SL->data[i][j].Lamp=2; 46 SL->data[i][j].Stool=4; 47 SL->data[i][j].The_table=4; 48 } 49 return SL; 50 51 } 52 SeqList *Int_SeqList() 53 { 54 SeqList *SL ; 55 SL = (SeqList *) malloc (sizeof(SeqList)); 56 SL->Last=-1; 57 return SL; 58 } 59 60 61 char getSex(){ 62 char sex; 63 while(1){ 64 fflush(stdin); 65 printf("请输入性别(M或F):"); 66 scanf("%c",&sex); 67 fflush(stdin); 68 if(sex==\'M\'||sex==\'F\'||sex==\'m\'||sex==\'f\') 69 break; 70 else 71 printf("输入错误,您只能输入字符M(男)或者F(女)!\n"); 72 } 73 return sex; 74 } 75 int getNo(SeqList *SL) 76 { 77 int i ,ch=1,j; 78 int no; 79 while(1) 80 { 81 82 printf("请输入学号1000-9999:"); 83 scanf("%d",&no); 84 for(i=0;i<=SL->Last;i++) 85 { 86 if(no==SL->Data[i].sid||no<1000||no>9999) 87 { 88 printf("输入错误或学号重复!\n");ch=0;break; 89 } 90 else 91 { 92 ch=1; 93 } 94 95 } 96 if(ch==1)return no; 97 } 98 99 } 100 101 get_floor(SeqList *SL,SeqList *L) 102 { 103 int floor; 104 int i; 105 while(1) 106 { 107 108 printf("请输入楼层(1-4):"); 109 scanf("%d",&floor); 110 if(floor>0&&floor<5) 111 break; 112 else 113 printf("输入错误,\n"); 114 } 115 return floor; 116 } 117 get_rid(SeqList *SL,SeqList *L) 118 { 119 int rid; 120 int i,flag,a; 121 while(1) 122 { 123 printf("请输入房间(1-30):"); 124 scanf("%d",&rid); 125 if(rid>=1&&rid<=30) 126 for(i=0;i<SL->Last;i++) 127 { 128 if(L->data[SL->Data[i].floor][rid].Bedspace==0||rid<1||rid>30) 129 { 130 while(1) 131 { 132 133 printf("此房间已住满人,输入别的房间号\n"); 134 scanf("%d",&a); 135 if(L->data[SL->Data[i].floor][a].Bedspace!=0&&rid>0&&rid<31) 136 return a; 137 138 } 139 140 141 } 142 143 } 144 return rid; 145 146 147 } 148 149 } 150 Student getStudent(SeqList *SL,SeqList *L) 151 { 152 Student s1; 153 s1.sid = getNo(SL); 154 printf("请输入姓名:"); 155 scanf("%s",s1.Name); 156 s1.Sex = getSex(); 157 printf("请输入年龄:"); 158 scanf("%d",&s1.Age); 159 printf("请输入班级:"); 160 scanf("%s",s1.Class); 161 s1.floor=get_floor(SL,L); 162 s1.rid=get_rid(SL,L); 163 164 165 return s1; 166 } 167 void Query_Facilities(SeqList *SL,SeqList *L)//查找设施是否完好 168 { 169 system("cls"); 170 int a,b; 171 printf("请输入你想查询的宿舍楼层和房间号:"); 172 scanf("%d %d",&a,&b); 173 if((a>=1&&a<=4)&&(b<=30&&b>=1)) 174 { 175 if(L->data[a][b].The_table==4) 176 printf("\n桌子设施完好"); 177 else if(L->data[a][b].The_table<4&&L->data[a][b].The_table>=1) 178 printf("\n有%d张桌子坏了",4-L->data[a][b].The_table); 179 if(L->data[a][b].Stool==4) 180 printf("\n凳子设施完好"); 181 else if(L->data[a][b].Stool<4&&L->data[a][b].Stool>=1) 182 printf("\n有%d张凳子坏了",4-L->data[a][b].Stool); 183 if(L->data[a][b].Fan==2) 184 printf("\n风扇完好"); 185 else if(L->data[a][b].Fan<2&&L->data[a][b].Fan>=1) 186 printf("\n有%d个风扇坏了",2-(L->data[a][b].Fan)); 187 if(L->data[a][b].Lamp==2) 188 printf("\n灯完好无缺"); 189 else if(L->data[a][b].Lamp<2&&L->data[a][b].Lamp>=1) 190 printf("\n有%d个灯坏了",2-L->data[a][b].Lamp); 191 } 192 } 193 SeqList *The_table_Warranty(SeqList *SL,SeqList *L)//桌子报修 194 { 195 system("cls"); 196 int a,b,c; 197 while(1) 198 { 199 printf("\n请输入你想查询的宿舍楼层和房间号:"); 200 scanf("%d %d",&a,&b); 201 printf("\n请输入你宿舍的桌子坏了几张:"); 202 scanf("%d",&c); 203 if((a>=1&&a<=4)&&(b<=30&&b>=1)) 204 { 205 if(c<=4&&c>=1) 206 { 207 L->data[a][b].The_table=4-c; 208 printf("\n你有%d张桌子坏了,我们已经知晓,一会上门为您维修\n",c); 209 printf("\n这是我们的联系方式110120"); 210 return L; 211 break; 212 } 213 214 else 215 { 216 printf("\n您输入的信息有错请重新输入:"); 217 printf("\n按任意键继续!"); 218 getch(); 219 } 220 221 } 222 } 223 224 225 } 226 SeqList *Stool_Warranty(SeqList *SL,SeqList *L)//凳子报修 227 { 228 system("cls"); 229 int a,b,c; 230 while(1) 231 { 232 printf("\n请输入你想查询的宿舍楼层和房间号:"); 233 scanf("%d %d",&a,&b); 234 printf("\n请输入你宿舍的凳子坏了几张:"); 235 scanf("%d",&c); 236 if((a>=1&&a<=4)&&(b<=30&&b>=1)) 237 { 238 if(c<=4&&c>=1) 239 { 240 L->data[a][b].Stool=4-c; 241 printf("\n你有%d张凳子坏了,我们已经知晓,一会上门为您维修\n",c); 242 printf("\n这是我们的联系方式110120"); 243 return L; 244 break; 245 } 246 247 else 248 { 249 printf("\n您输入的信息有错请重新输入:"); 250 printf("\n按任意键继续!"); 251 getch(); 252 } 253 254 } 255 } 256 } 257 SeqList *Fan_Warranty(SeqList *SL,SeqList *L)//风扇报修 258 { 259 system("cls"); 260 int a,b,c; 261 while(1) 262 { 263 printf("\n请输入你想查询的宿舍楼层和房间号:"); 264 scanf("%d %d",&a,&b); 265 printf("\n请输入你宿舍的风扇坏了几个:"); 266 scanf("%d",&c); 267 if((a>=1&&a<=4)&&(b<=30&&b>=1)) 268 { 269 if(c<=2&&c>=1) 270 { 271 L->data[a][b].Fan=2-c; 272 printf("\n你有%d个风扇坏了,我们已经知晓,一会上门为您维修\n",c); 273 printf("\n这是我们的联系方式110120"); 274 return L; 275 break; 276 } 277 278 else 279 { 280 printf("\n您输入的信息有错请重新输入:"); 281 printf("\n按任意键继续!"); 282 getch(); 283 } 284 } 285 } 286 } 287 SeqList *lamp_Warranty(SeqList *SL,SeqList *L)//灯报修 288 { 289 system("cls"); 290 int a,b,c; 291 while(1) 292 { 293 printf("\n请输入你想查询的宿舍楼层和房间号:"); 294 scanf("%d %d",&a,&b); 295 printf("\n请输入你宿舍的灯坏了几个:"); 296 scanf("%d",&c); 297 if((a>=1&&a<=4)&&(b<=30&&b>=1)) 298 { 299 if(c<=2&&c>=1) 300 { 301 L->data[a][b].Lamp=2-c; 302 printf("\n你有%d个灯坏了,我们已经知晓,一会上门为您维修\n",c); 303 printf("\n这是我们的联系方式110120"); 304 return L; 305 } 306 307 else 308 { 309 printf("\n您输入的信息有错请重新输入:"); 310 printf("\n按任意键继续!"); 311 getch(); 312 } 313 } 314 } 315 } 316 void Warranty(SeqList *SL,SeqList *L)//报修 317 { 318 system("cls"); 319 int a; 320 while(1) 321 { 322 printf("\t\t*****************************************\n"); 323 printf("\t\t****** 报修设备 ******\n"); 324 printf("\t\t*****************************************\n"); 325 printf("\t\t\t1.桌子报修"); 326 printf("\n\t\t\t2.凳子报修"); 327 printf("\n\t\t\t3.风扇报修"); 328 printf("\n\t\t\t4.灯报修"); 329 printf("\n\t\t\t5.返回上一级\n"); 330 printf("\n请选择:"); 331 scanf("%d",&a); 332 if(a==1) 333 { 334 The_table_Warranty(SL,L);getch();break; 335 } 336 else if(a==2) 337 { 338 Stool_Warranty(SL,L);getch();break; 339 } 340 else if(a==3) 341 { 342 Fan_Warranty(SL,L);getch();break; 343 } 344 else if(a==4) 345 { 346 lamp_Warranty(SL,L);getch();break; 347 } 348 else 349 return; 350 } 351 } 352 353 menu3(SeqList *SL,SeqList *L) 354 { 355 int i; 356 system("cls"); 357 while(1) 358 { 359 printf("\t\t*****************************************\n"); 360 printf("\t\t****** 欢迎进入 ******\n"); 361 printf("\t\t*****************************************\n"); 362 printf("\t\t\t1.根据宿舍查询基本设施\n"); 363 printf("\t\t\t2.搜索查询所有的故障设备并报修\n"); 364 printf("\t\t\t3.返回主菜单"); 365 printf("\n请选择:"); 366 scanf("%d",&i); 367 if(i==1) 368 { 369 Query_Facilities(SL,L);getch();break; 370 } 371 else if(i==2) 372 { 373 Warranty(SL,L);getch();break; 374 } 375 else 376 { 377 getch();break; 378 } 379 } 380 } 381 382 383 384 385 386 void Modify_name(SeqList *SL)//修改姓名 387 { 388 system("cls"); 389 int a,flag=0; 390 char s[15]; 391 while(1) 392 { 393 int i; 394 int w; 395 printf("请输入学号进行查询\n"); 396 scanf("%d",&w); 397 for(i=0;i<=SL->Last ;i++) 398 { 399 if(SL->Data[i].sid==w) 400 { 401 flag++; 402 printf("\t学号:%d\t姓名:%s\t性别:%c\t年龄:%d\t班级:%s\t楼层:%d\t宿舍号:%d\n",SL->Data[i].sid,SL->Data[i].Name,SL->Data[i].Sex,SL->Data[i].Age,SL->Data[i].Class,SL->Data[i].floor,SL->Data[i].rid); 403 printf("是否修改学生的姓名\n1.是\n2.否\n"); 404 scanf("%d",&a); 405 if(a==1) 406 { 407 printf("\n请输入新的姓名:"); 408 scanf("%s",s); 409 strcpy(SL->Data[i].Name,s); 410 printf("\n修改成功!"); 411 412 getch(); 413 return; 414 } 415 else 416 return; 417 } 418 419 } 420 if(flag==0) 421 printf("没有该学生信息!重新输入\n"); 422 } 423 } 424 void Modify_sex(SeqList *SL)//修改性别 425 { 426 system("cls"); 427 int a,flag=0; 428 char s; 429 while(1) 430 { 431 int i,flag=0; 432 int w; 433 printf("请输入学号进行查询\n"); 434 scanf("%d",&w); 435 for(i=0;i<=SL->Last ;i++) 436 { 437 if(SL->Data[i].sid==w) 438 { 439 printf("\t学号:%d\t姓名:%s\t性别:%c\t年龄:%d\t班级:%s\t楼层:%d\t宿舍号:%d\n",SL->Data[i].sid,SL->Data[i].Name,SL->Data[i].Sex,SL->Data[i].Age,SL->Data[i].Class,SL->Data[i].floor,SL->Data[i].rid); 440 printf("是否修改学生的性别\t1.是\n2.否\n"); 441 scanf("%d",&a); 442 if(a==1) 443 { 444 printf("\n请输入新的性别:"); 445 446 SL->Data[i].Sex=getSex(); 447 printf("\n修改成功!"); 448 449 getch(); 450 return; 451 } 452 else return; 453 } 454 455 } 456 if(flag==0) 457 printf("没有该学生信息!重新输入\n"); 458 459 } 460 } 461 void Modify_class(SeqList *SL)//修改班级 462 { 463 system("cls"); 464 int a; 465 char s[20]; 466 while(1) 467 { 468 int i,flag=0; 469 int w; 470 printf("请输入学号进行查询\n"); 471 scanf("%d",&w); 472 for(i=0;i<=SL->Last ;i++) 473 { 474 if(SL->Data[i].sid==w) 475 { 476 printf("\t学号:%d\t姓名:%s\t性别:%c\t年龄:%d\t班级:%s\t楼层:%d\t宿舍号:%d\n",SL->Data[i].sid,SL->Data[i].Name,SL->Data[i].Sex,SL->Data[i].Age,SL->Data[i].Class,SL->Data[i].floor,SL->Data[i].rid); 477 printf("是否修改学生的班级\t1.是\n2.否"); 478 scanf("%d",&a); 479 if(a==1) 480 { 481 printf("\n请输入新的班级:"); 482 scanf("%s",s); 483 strcpy(SL->Data[i].Class,s); 484 printf("\n修改成功!"); 485 486 getch(); 487 return; 488 } 489 else return; 490 } 491 } 492 if(flag==0) 493 printf("没有该学生信息!重新输入\n"); 494 } 495 } 496 void Modify_age(SeqList *SL)//修改年龄 497 { 498 system("cls"); 499 int a,flag=0; 500 int s; 501 while(1) 502 { 503 int i; 504 int w; 505 printf("请输入学号进行查询\n"); 506 scanf("%d",&w); 507 for(i=0;i<=SL->Last ;i++) 508 { 509 if(SL->Data[i].sid==w) 510 { 511 printf("\t学号:%d\t姓名:%s\t性别:%c\t年龄:%d\t班级:%s\t楼层:%d\t宿舍号:%d\n",SL->Data[i].sid,SL->Data[i].Name,SL->Data[i].Sex,SL->Data[i].Age,SL->Data[i].Class,SL->Data[i].floor,SL->Data[i].rid); 512 printf("是否修改学生的年龄\t\n1.是\n2.否\n"); 513 scanf("%d",&a); 514 if(a==1) 515 { 516 printf("\n请输入新的年龄:"); 517 scanf("%d",&s); 518 SL->Data[i].Age=s; 519 printf("\n修改成功!"); 520 521 getch(); 522 return; 523 } 524 else return; 525 } 526 527 } 528 if(flag==0) 529 printf("没有该学生信息!重新输入\n"); 530 } 531 } 532 Modify_sid(SeqList *SL) 533 { 534 system("cls"); 535 int a,flag=0; 536 char s; 537 while(1) 538 { 539 int i; 540 int w; 541 printf("请输入学号进行查询\n"); 542 scanf("%d",&w); 543 for(i=0;i<=SL->Last ;i++) 544 { 545 if(SL->Data[i].sid==w) 546 { 547 flag++; 548 printf("学号:%d\t姓名:%s\t性别:%c\t年龄:%d\t班级:%s\t楼层:%d\t宿舍号:%d\n",SL->Data[i].sid,SL->Data[i].Name,SL->Data[i].Sex,SL->Data[i].Age,SL->Data[i].Class,SL->Data[i].floor,SL->Data[i].rid); 549 printf("是否修改学生的学号\n1.是\n2.否\n"); 550 scanf("%d",&a); 551 if(a==1) 552 { 553 SL->Data[i].sid=getNo(SL); 554 printf("\n修改成功!"); 555 556 getch(); 557 return; 558 } 559 else 560 return; 561 } 562 563 564 } 565 if(flag==0) 566 printf("没有该学生信息!重新输入\n"); 567 568 } 569 } 570 menu2(SeqList *SL) 571 { 572 system("cls"); 573 int i; 574 if(SL->Last==-1) 575 { 576 printf("没有学生信息!无法进行修改\n");return 0; 577 } 578 while(1) 579 { 580 printf("\t\t*****************************************\n"); 581 printf("\t\t****** 欢迎进入 ******\n"); 582 printf("\t\t*****************************************\n"); 583 printf("\t\t\t1.修改学生学号\n"); 584 printf("\t\t\t2.修改学生姓名\n"); 585 printf("\t\t\t3.修改学生性别\n"); 586 printf("\t\t\t4.修改学生班级\n"); 587 printf("\t\t\t5.修改学生年龄\n"); 588 printf("\t\t\t6.返回主菜单\n"); 589 scanf("%d",&i); 590 if(i==1) 591 { 592 Modify_sid(SL);getch();break; 593 } 594 else if(i==2) 595 { 596 Modify_name(SL);getch();break; 597 } 598 else if(i==3) 599 { 600 Modify_sex(SL);getch();break; 601 } 602 else if(i==4) 603 { 604 Modify_class(SL);getch();break; 605 } 606 else if(i==5) 607 { 608 Modify_age(SL);getch();break; 609 } 610 else 611 return; 612 } 613 } 614 615 616 add_Room(SeqList *SL,SeqList *L) 617 { 618 system("cls"); 619 int a; 620 while(1) 621 { 622 623 624 SL->Last++; 625 SL->Data[SL->Last]=getStudent(SL,L); 626 L->data[SL->Data[SL->Last].floor][SL->Data[SL->Last].rid].Bedspace--; 627 printf("(1)继续输入(0)退出\n"); 628 scanf("%d",&a); 629 if(a==0)return; 630 system("pause"); 631 } 632 } 633 display(SeqList *SL) 634 { 635 system("cls"); 636 int i; 637 if(SL->Last==-1) 638 { 639 printf("没有信息!\n");return 0; 640 } 641 printf("\t\t\t\t学生信息\n"); 642 printf("\t学号\t姓名\t性别\t年龄\t班级\t楼层\t宿舍号\n"); 643 for(i=0;i<=SL->Last;i++) 644 printf("\t%d\t %s\t%c\t%d\t%s\t %d\t %d\n",SL->Data[i].sid,SL->Data[i].Name,SL->Data[i].Sex,SL->Data[i].Age,SL->Data[i].Class,SL->Data[i].floor,SL->Data[i].rid); 645 printf("\n\n\n"); 646 } 647 648 menu() 649 { int i; 650 system("cls"); 651 printf("\t\t*****************************************\n"); 652 printf("\t\t************ 宿舍管理 **************\n"); 653 printf("\t\t*****************************************\n"); 654 printf("\t\t\t1.读取信息\n"); 655 printf("\t\t\t2.添加学生住宿信息\n"); 656 printf("\t\t\t3.浏览学生住宿信息\n"); 657 printf("\t\t\t4.查询学生住宿信息\n"); 658 printf("\t\t\t5.修改学生信息\n"); 659 printf("\t\t\t6.修改学生宿舍信息\n"); 660 printf("\t\t\t7.宿舍设施查询和维护\n"); 661 printf("\t\t\t8.删除学生住宿信息\n"); 662 printf("\t\t\t9.A B O U T\n"); 663 printf("\t\t\t10.保存退出\n"); 664 printf("请选择:"); 665 scanf("%d",&i); 666 return i; 667 } 668 669 void OpenFile(SeqList *SL)//载入文件信息 670 { FILE *fp; 671 if((fp = fopen("Student.txt","r+"))==NULL) 672 { printf("打开文件失败\n"); 673 system("PAUSE"); 674 exit(1); 675 } 676 do{SL->Last++;} 677 while( fread(&SL->Data[SL->Last],sizeof(Student),1,fp)==1); 678 SL->Last--;//将last值指向现有末尾元素下标 679 printf("读取完毕"); 680 fclose(fp); 681 } 682 void Open_room(SeqList *SL,SeqList *L)//载入文件信息 683 { FILE *fp;int i,j; 684 if((fp = fopen("Room.txt","r+"))==NULL) 685 { printf("打开文件失败\n"); 686 system("PAUSE"); 687 exit(1); 688 } 689 690 691 for(j=1;j<5;j++) 692 for(i=1;i<31;i++) 693 fread(&L->data[j][i],sizeof(Room),1,fp); 694 //将last值指向现有末尾元素下标 695 printf("读取完毕"); 696 fclose(fp); 697 } 698 void Save_room(SeqList *SL,SeqList *L) //写入文件的语句 699 {FILE *fp; int i,j; 700 if((fp=fopen("Room.txt","w"))==NULL) 701 { printf("打开文件失败"); 702 printf("打开文件失败\n"); 703 exit(1); 704 } 705 706 for(j=1;j<5;j++) 707 for(i=1;i<31;i++) 708 { if(fwrite(&L->data[j][i],sizeof(Room),1,fp)!=1) 709 printf("写入错误!"); 710 } 711 printf("\n保存完毕\n"); 712 fclose(fp); 713 } 714 void SaveFile(SeqList *SL) //写入文件的语句 715 {FILE *fp; int i; 716 if((fp=fopen("Student.txt","w"))==NULL) 717 { printf("打开文件失败"); 718 printf("打开文件失败\n"); 719 exit(1); 720 } 721 for(i=0;i<=SL->Last;i++) 722 { if(fwrite(&SL->Data[i],sizeof(Student),1,fp)!=1) 723 printf("写入错误!"); 724 } 725 printf("\n保存完毕\n"); 726 fclose(fp); 727 } 728 void Accommodation_check(SeqList *SL,SeqList *L)//查询宿舍信息 729 { 730 if(SL->Last==-1) 731 { 732 printf("没有信息!\n");return 0; 733 } 734 system("cls"); 735 int a; 736 while(1) 737 { 738 printf("\t\t*****************************************\n"); 739 printf("\t\t****** 宿舍信息 ******\n"); 740 printf("\t\t*****************************************\n"); 741 printf("\t\t\t1.按宿舍号查找\n"); 742 printf("\t\t\t2.按学生号查找\n"); 743 printf("\t\t\t3.返回上一级\n"); 744 scanf("%d",&a); 745 if(a==1) 746 { 747 Find_room1(SL);getch();break; 748 } 749 else if(a==2) 750 { 751 Find_sid(SL);getch();break; 752 } 753 else 754 return ; 755 } 756 } 757 int Find_room1(SeqList *SL)//宿舍全部查询 758 { 759 int a,b,c; 760 int i,j,w; 761 int flag=0; 762 while(1) 763 { 764 printf("请输入要查寻得楼层(1-4)"); 765 scanf("%d",&i); 766 if(i>=1&&i<=4) 767 break; 768 else printf("输入错误请重新输入"); 769 770 } 771 while(1) 772 { 773 printf("请输入寝室(1-30)"); 774 scanf("%d",&j); 775 if(j>0&&j<=30) 776 break; 777 else printf("输入错误请重新输入"); 778 779 } 780 for(a=1;a<=4;a++) 781 { 782 for(b=1;b<=30;b++) 783 { 784 for(c=0;c<=SL->Last ;c++) 785 if(SL->Data[c].floor==i&&SL->Data[c].rid==j) 786 { 787 printf("\t学号:%d\t姓名:%s\t性别:%c\t年龄:%d\t班级:%s\t楼层:%d\t宿舍号:%d\n",SL->Data[c].sid,SL->Data[c].Name,SL->Data[c].Sex,SL->Data[c].Age,SL->Data[c].Class,SL->Data[c].floor,SL->Data[c].rid); 788 flag++; 789 } 790 791 if(flag==0)printf("该宿舍无人员!\n"); 792 return 0; 793 } 794 } 795 796 797 } 798 799 int Find_sid(SeqList *SL)//学号查询 800 { 801 int i; 802 int w; 803 804 printf("请输入学号进行查询"); 805 scanf("%d",&w); 806 for(i=0;i<=SL->Last ;i++) 807 { 808 if(SL->Data[i].sid==w) 809 { 810 printf("\t学号:%d\t姓名:%s\t性别:%c\t年龄:%d\t班级:%s\t楼层:%d\t宿舍号:%d\n",SL->Data[i].sid,SL->Data[i].Name,SL->Data[i].Sex,SL->Data[i].Age,SL->Data[i].Class,SL->Data[i].floor,SL->Data[i].rid); 811 return SL->Last; 812 } 813 814 } 815 816 } 817 Delete(SeqList *SL,SeqList *L)//删除 818 { 819 system("cls"); 820 if(SL->Last==-1) 821 { 822 printf("没有信息!\n");return 0; 823 } 824 int a,flag=0,cont; 825 while(1) 826 { 827 system("cls"); 828 printf("\t\t\t1.按学号查找删除\n"); 829 printf("\t\t\t2.全部删除\n"); 830 printf("\t\t\t3.返回上一级\n"); 831 scanf("%d",&cont); 832 if(cont==1) 833 { 834 while(1) 835 { 836 int i,j; 837 int w; 838 printf("请输入学号进行删除\n"); 839 scanf("%d",&w); 840 for(i=0;i<=SL->Last ;i++) 841 { 842 if(SL->Data[i].sid==w) 843 { 844 flag++; 845 printf("学号:%d\t姓名:%s\t性别:%c\t年龄:%d\t班级:%s\t楼层:%d\t宿舍号:%d\n",SL->Data[i].sid,SL->Data[i].Name,SL->Data[i].Sex,SL->Data[i].Age,SL->Data[i].Class,SL->Data[i].floor,SL->Data[i].rid); 846 printf("是否删除学生信息\n1.是\n2.否\n"); 847 scanf("%d",&a); 848 if(a==1) 849 { 850 for(j=i;j<=SL->Last;j++) 851 { 852 SL->Data[j-1]=SL->Data[j]; 853 854 } 855 L->data[SL->Data[i].floor][SL->Data[i].rid].Bedspace++; 856 SL->Last--; 857 printf("删除成功"); 858 getch(); 859 return; 860 } 861 else 862 return; 863 } 864 865 866 } 867 if(flag==0)printf("没有该学生信息!重新输入\n"); 868 869 } 870 } 871 else if(cont==2) 872 { 873 printf("是否删除全部学生信息\n1.是\n2.否\n"); 874 scanf("%d",&a); 875 if(a==1) 876 { 877 878 SL->Last=-1; 879 printf("删除成功"); 880 getch(); 881 return; 882 } 883 else 884 return; 885 } 886 else 887 return; 888 getch(); 889 } 890 891 } 892 void menu0() 893 { 894 int j,i; 895 int arrge[x][y]={1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 896 1,0,0,0,0,0,0,2,2,2,0,0,0,2,2,2,0,0,0,0,0,0, 897 1,0,0,0,0,0,2,0,0,0,2,0,2,0,0,0,2,0,0,0,0,0, 898 1,0,0,0,0,2,0,0,0,0,0,2,0,0,0,0,0,2,0,0,0,0, 899 1,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, 900 1,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0, 901 1,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0, 902 1,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0, 903 1,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0, 904 1,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0, 905 1,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, 906 1,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0, 907 1,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0, 908 1,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0, 909 1,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0,0,0,0,0,0,0, 910 1,0,0,0,0,0,0,0,0,2,0,0,0,2,0,0,0,0,0,0,0,0, 911 1,0,0,0,0,0,0,0,0,0,2,0,2,0,0,0,0,0,0,0,0,0, 912 1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0, 913 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 914 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 915 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 916 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 917 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}; 918 919 for(j=0;j<x;j++) 920 { 921 922 for(i=0;i<y;i++) 923 { 924 switch(arrge[j][i]) 925 { 926 case 0:printf("※"); break; 927 case 1:printf(" ");break; 928 case 2:printf("★"); break; 929 } 930 931 } 932 printf("\n"); 933 934 } 935 } 936 void about() 937 { 938 printf("///////////////////////////////////////////////////////////////////////////////\n"); 939 printf("///////////////////////////////////////////////////////////////////////////////\n"); 940 printf("//////////////////////////////////////////////////////////////////////////////\n"); 941 char s[]="-----------------------Welcome to the 207 dormitory---------------------------\n\n============Name:Doublekai ============Name:翟砀丰\n============Sex:man ============Sex:man\n============Mail:18656168754@163.com ============Mail:1161841173@qq.com\n\n\t\t\t============Name:张浩============\n\t\t\t============Sex:man============\n\t\t\t============Mail:2461429560@qq.com============\n\n\n\n 按任意键返回.... \n\n\n\n____________________________本版权最终归四北207所有!!____________________________"; 942 int i; 943 for(i=0;i<strlen(s);i++) 944 { Sleep(25); 945 putchar(s[i]); 946 } 947 system("pause"); 948 menu(); 949 950 951 } 952 swop_room(SeqList *SL,SeqList *L) 953 { 954 int i,cont,w; 955 if(SL->Last==-1) 956 { 957 printf("没有信息!\n");return 0; 958 } 959 printf("请输入学号进行查询\n"); 960 scanf("%d",&w); 961 for(i=0;i<=SL->Last ;i++) 962 if(SL->Data[i].sid==w) 963 { 964 printf("学号:%d\t姓名:%s\t性别:%c\t年龄:%d\t班级:%s\t楼层:%d\t宿舍号:%d\n",SL->Data[i].sid,SL->Data[i].Name,SL->Data[i].Sex,SL->Data[i].Age,SL->Data[i].Class,SL->Data[i].floor,SL->Data[i].rid); 965 break; 966 } 967 SL->Data[i].floor=get_floor(SL,L); 968 SL->Data[i].rid=get_rid(SL,L); 969 L->data[SL->Data[i].floor][SL->Data[i].rid].Bedspace--; 970 printf("交换成功"); 971 return ; 972 } 973 swop_rid(SeqList *SL,SeqList *L) 974 { 975 int i,cont_1=0,cont_2=0,w,j,a,t,T; 976 if(SL->Last==-1) 977 { 978 printf("没有信息!\n");return 0; 979 } 980 printf("请输入学号进行查询\n"); 981 scanf("%d",&w); 982 for(i=0;i<=SL->Last ;i++) 983 if(SL->Data[i].sid==w) 984 { 985 printf("学号:%d\t姓名:%s\t性别:%c\t年龄:%d\t班级:%s\t楼层:%d\t宿舍号:%d\n",SL->Data[i].sid,SL->Data[i].Name,SL->Data[i].Sex,SL->Data[i].Age,SL->Data[i].Class,SL->Data[i].floor,SL->Data[i].rid); 986 cont_2++; 987 break; 988 } 989 if(cont_2==0) 990 { 991 printf("没有此人!");return; 992 } 993 994 printf("请输入学号进行查询\n"); 995 scanf("%d",&a); 996 for(j=0;j<=SL->Last ;j++) 997 if(SL->Data[j].sid==a) 998 { 999 cont_2++; 1000 printf("学号:%d\t姓名:%s\t性别:%c\t年龄:%d\t班级:%s\t楼层:%d\t宿舍号:%d\n",SL->Data[j].sid,SL->Data[j].Name,SL->Data[j].Sex,SL->Data[j].Age,SL->Data[j].Class,SL->Data[j].floor,SL->Data[j].rid); 1001 break; 1002 } 1003 if(cont_1==0) 1004 { 1005 printf("没有此人!");return; 1006 } 1007 t=SL->Data[i].floor; 1008 SL->Data[i].floor=SL->Data[j].floor; 1009 SL->Data[j].floor=t; 1010 T=SL->Data[i].floor; 1011 SL->Data[i].rid=SL->Data[j].rid; 1012 SL->Data[j].rid=t; 1013 printf("交换成功"); 1014 1015 1016 } 1017 menu4(SeqList *SL,SeqList *L) 1018 { 1019 system("cls"); 1020 int i; 1021 while(1) 1022 { 1023 printf("\t\t*****************************************\n"); 1024 printf("\t\t****** 欢迎进入 ******\n"); 1025 printf("\t\t*****************************************\n"); 1026 printf("\t\t\t1.交换宿舍\n"); 1027 printf("\t\t\t2.调换宿舍\n"); 1028 scanf("%d",&i); 1029 if(i==1) 1030 { 1031 swop_rid(SL,L);getch();break; 1032 } 1033 else if(i==2) 1034 { 1035 swop_room(SL,L);getch();break; 1036 } 1037 1038 else 1039 { 1040 getch();break; 1041 } 1042 } 1043 } 1044 main() 1045 { 1046 SeqList *SL,*L; 1047 SL=Int_SeqList(); 1048 L=Int_Room(); 1049 char pass[7]="haha",pas[7]; 1050 int p=3,i=0,time=2; 1051 while(i<p) 1052 { 1053 menu0(); 1054 printf("\t\t请输入密码"); 1055 scanf("%s",pas); 1056 if(strcmp(pass,pas)==0) 1057 { 1058 printf("密码正确"); 1059 system("cls"); 1060 while(time>=0) 1061 { 1062 1063 printf("\r\t\t\t还有%d秒进入系统",time--); 1064 Sleep(1000); 1065 } 1066 while(1) 1067 { 1068 switch(menu()) 1069 { 1070 case 1: OpenFile(SL);Open_room(SL,L);system("pause");break; 1071 case 2: add_Room(SL,L);system("pause");break; 1072 case 3: display(SL);system("pause");break; 1073 case 4: Accommodation_check(SL,L);system("pause");break; 1074 case 5:menu2(SL);system("pause");break; 1075 case 6:menu4(SL,L); system("pause");break; 1076 case 7:menu3(SL,L); system("pause");break; 1077 case 8:Delete(SL,L);system("pause");break; 1078 case 9:system("cls");about();system("pause");break; 1079 1080 case 10: SaveFile(SL);Save_room(SL,L);system("pause");return 0; 1081 } 1082 } 1083 1084 return 0; 1085 } 1086 else 1087 { 1088 system("cls"); 1089 printf("密码错误%d次\n",++i); 1090 } 1091 } 1092 printf("你的密码输入次数达到上限"); 1093 while(time>=0) 1094 { 1095 printf("\r还有%d秒退出系统",time--); 1096 Sleep(1000); 1097 } 1098 return 0; 1099 }
2017-06-30 09:55:10
相关文章: