1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<conio.h> 5 6 int roomnum[5]={301,302,303,304,305}; 7 8 int menu(); 9 struct stu 10 { 11 char name[10]; 12 char sex[3]; 13 int empty=0; 14 } Rooms[5]; 15 16 void search() 17 { 18 printf("可以入住的房间有:"); 19 for(int i=0;i<5;i++) 20 { 21 if(Rooms[i].empty==0) 22 { 23 printf("%d ",301+i); 24 } 25 } 26 printf("\n"); 27 } 28 29 int check(int room) 30 { 31 32 if(room>305||room<301) 33 return 0; 34 if(Rooms[room-301].empty==0) 35 return 1; 36 else 37 return 0; 38 } 39 40 void Getout() 41 { 42 system("cls"); 43 int getoutnum; 44 char a; 45 printf("请输入退房顾客的房间号:\n"); 46 scanf("%d",&getoutnum); 47 printf("确认输入Y,返回主菜单输入N\n"); 48 a=getch(); 49 if(a==‘Y‘||a==‘y‘) 50 { 51 strcpy(Rooms[getoutnum-301].name,"\0"); 52 strcpy(Rooms[getoutnum-301].sex,"\0"); 53 Rooms[getoutnum-301].empty=0; 54 menu(); 55 } 56 else if(a==‘N‘||a==‘n‘) 57 menu(); 58 } 59 60 int Findout() 61 { 62 system("cls"); 63 printf("提示:查询不守法,亲人两行泪\n请输入你所需要查找的信息,\n按姓名搜索在前面加1,按房间搜索在前面加2\n"); 64 char a; 65 int k=0; 66 char name[10]; 67 int room; 68 a=getchar(); 69 if(a==‘1‘) 70 { 71 scanf("%s",name); 72 for(int i=0;i<5;i++) 73 { 74 if(strcmp(Rooms[i].name,name)==0) 75 { 76 k=1; 77 printf("姓名:%s\n性别:%s\b\n房间号:%d\n\n",Rooms[i].name,Rooms[i].sex,301+i); 78 printf("输入任意键回到主菜单"); 79 getch(); 80 getch(); 81 menu(); 82 } 83 } 84 if(k==0) 85 { 86 printf("查无此人。"); 87 menu(); 88 } 89 90 } 91 else if(a==‘2‘) 92 { 93 scanf("%d",&room); 94 if(Rooms[room-301].empty==1) 95 { 96 printf("姓名:%s\n性别:%s\b\n房间号:%d\n\n",Rooms[room-301].name,Rooms[room-301].sex,room); 97 printf("输入任意键回到主菜单"); 98 getch(); 99 getch(); 100 menu(); 101 } 102 else 103 { 104 printf("查无此人。"); 105 menu(); 106 } 107 } 108 else 109 { 110 printf("输入错误,请重新输入:"); 111 Findout(); 112 } 113 } 114 void Takein() 115 { 116 system("cls"); 117 char a; 118 char name_a[10]; 119 char sex_a[3]; 120 search(); 121 int room; 122 printf("请按如下格式输入:\姓名:张三\n性别:男\n入住房号:301\n"); 123 printf("姓名:"); scanf("%s",name_a); 124 printf("性别:"); scanf("%s",sex_a); 125 printf("入住房号:"); scanf("%d",&room); 126 if(check(room)==1) 127 { 128 strcpy(Rooms[room-301].name,name_a); 129 strcpy(Rooms[room-301].sex,sex_a); 130 Rooms[room-301].empty=1; 131 } 132 else 133 { 134 printf("你的输入有误,请重新输入:\n"); 135 Takein(); 136 } 137 printf("退出请输入Y,登记输入N\n"); 138 a=getch(); 139 if(a==‘Y‘||a==‘y‘) 140 menu(); 141 else if(a==‘N‘||a==‘n‘) 142 Takein(); 143 } 144 145 int menu() 146 { 147 system("cls"); 148 printf(" 欢迎您,请输入对应数字进行操作\n"); 149 printf("***********1.入住办理***********\n"); 150 printf("***********2.退房办理***********\n"); 151 printf("***********3.人员搜索***********\n"); 152 char a=getch(); 153 if(a==‘1‘) 154 Takein(); 155 else if(a==‘2‘) 156 Getout(); 157 else if(a==‘3‘) 158 Findout(); 159 else 160 { 161 printf("输入错误,请重新输入:"); 162 menu(); 163 } 164 } 165 166 int main() 167 { 168 menu(); 169 return 0; 170 }
好久没有敲代码了,月底的二级考试好虚啊
原文:https://www.cnblogs.com/ncoheart/p/10486100.html