1、/*题目:旅店信息管理系统*小组组员:闫若琳 戴雨晨 马渊沐 张子飞 李闯 王浩 崔以博 孙浩浩 李春普 温健成*/#include #include #include #include #define MIN 1#define MAX 30#define LEN sizeof(struct Hotel)/用LEN替换结构体长度void regeist();void out_information();void search_number();void show_all();void search_name();void change();void fire();struct Hotel *l
2、oad();FILE *fp; struct Hotel int room_number;char name 20;char sex10;char ID 20;float paid10;int inyear ;int inmonth ;int inday ;struct Hotel *next ;struct Hotel *load() /定义load函数读取目前信息,并存到内存链表中struct Hotel *head,*pb, *s ;pb=(struct Hotel *)malloc(LEN); /开辟新节点s =(struct Hotel *)malloc(LEN);if(pb=NUL
3、L)|(s=NULL)printf (动态内存分配失败!n);getch();exit(0);if(fp=fopen(resturant.txt,rb)=NULL)printf (无法打开文件!n);getch();exit(0);head = pb;while (fread (s,LEN,1,fp) /读取目前信息,并存到链表中pb-next = s;pb = s;s = (struct Hotel *)malloc(LEN);pb-next =NULL;return head ;/返回链表头指针int main ()/崔以博、孙浩浩 char choice ;do printf (nn-欢
4、迎使用旅店信息管理系统-nn); printf (1.查看旅店信息n2.查看某一房间信息n3.查看旅客信息n); printf (4.查找某一旅客信息n5.旅客入住n6.旅客换房n7.旅客退房n8.退出n); printf (n-n); choice=getch();switch (choice) case 1:out_information();break; case 2:search_number();break; case 3:show_all();break; case 4:search_name();break; case 5:regeist();break; case 6:chan
5、ge();break; case 7:fire();break; case 8:exit(0);break; default :printf (Error !);break ;printf (nn请按任意键继续 !n);getch();system(cls);while(1);return 0 ;void out_information()/张子飞:定义out_information函数,完成查看旅店信息功效FILE *fp;char ch ;if (fp=fopen(information.txt,r)=NULL) printf (无法打开文件!n);getch(); exit(0);ch=
6、fgetc(fp);system(cls);printf(nnttt旅店信息介绍: (若没有信息请返回创建);printf (n-nnt);while (ch!=EOF)putchar(ch);ch=fgetc(fp);fclose(fp);void search_number ()/李春普、温健成:定义search_number函数,用来完成查看某一房间信息char ch2 ;int room_number ;struct Hotel *head, *pa ;head=load();printf (n请输入需要查看房间序号:(%d%d):,MIN,MAX);scanf (%d,&room_n
7、umber);pa= head-next;if (room_numberMAX)printf (anError!);return ;doif (pa)if(room_number=pa-room_number)/假如找到对应信息,则输出printf (n);printf (roomnumber:t%d,pa-room_number);printf (n);printf (name:tt%s,pa-name);printf (n);printf (sex:tt%s,pa-sex);printf (n);printf (ID:tt%s,pa-ID);printf (n);printf (paid:
8、tt%s,pa-paid);printf (n);printf (%d %d %d,pa-inyear,pa-inmonth,pa-inday);printf (n);printf (n请选择是否继续查看信息(y/n):n);scanf (%s,ch);if(strcmp(ch,Y)!=0)&(strcmp(ch,y)!=0)return;elseprintf (n请输入需要查看房间序号:(%d%d):,MIN,MAX);scanf (%d,&room_number);pa= head-next;if (room_numberMAX)printf ( 无此房间!);return;continu
9、e ;pa = pa-next;elseprintf (n该房间还没有旅客入住);return;while(1);void show_all()/戴雨晨:定义是show_all函数,用来显示全部旅客信息struct Hotel *head, *pa ;head=load();pa= head-next;printf (n全部入住旅客信息以下:n);while (pa)/显示全部旅客信息printf (n);printf (roomnumber:t%d,pa-room_number);printf (n);printf (name:tt%s,pa-name);printf (n);printf
10、(sex:tt%s,pa-sex);printf (n);printf (ID:tt%s,pa-ID);printf (n);printf (paid:tt%s,pa-paid);printf (n);printf (date:tt%d %d %d,pa-inyear,pa-inmonth,pa-inday);printf (n);pa = pa-next;void search_name ()/马渊沐:定义search_name函数,用来完成查看某一旅客信息char ch2 ;char inname20 ;/用数组inname20来储存需要查询旅客namestruct Hotel *head
11、, *pa ;head=load();printf (n请输入需要查看旅客姓名:);scanf (%s,inname);pa= head-next;doif (pa)if(strcmp(inname,pa-name)=0)printf (n);printf (roomnumber:t%d,pa-room_number);printf (n);printf (name:tt%s,pa-name);printf (n);printf (sex:tt%s,pa-sex);printf (n);printf (ID:tt%s,pa-ID);printf (n);printf (paid:tt%s,pa
12、-paid);printf (n);printf (date:tt%d %d %d,pa-inyear,pa-inmonth,pa-inday);printf (n);printf (n请选择是否继续查看信息(y/n):n);scanf (%s,ch);if(strcmp(ch,Y)!=0)&(strcmp(ch,y)!=0)return;elseprintf (n请输入需要查看旅客姓名:);scanf (%s,inname);pa= head-next;continue ;pa = pa-next;else printf (n没有查到该旅客信息);return ;while(1);void
13、regeist()/闫若琳:定义regeist函数实现入住功效char ch2 ;int number ;struct Hotel *head,*p1,*p2,*pa;head=load();pa= head-next;printf (n已入住房间:n);while (pa)printf (n);printf (roomnumber:t%d,pa-room_number);pa = pa-next; fclose(fp);if(fp=fopen(resturant.txt,a+)=NULL)printf (无法打开文件!n);getch();exit(0);head=NULL;p1=(stru
14、ct Hotel *)malloc(LEN);p2=(struct Hotel *)malloc(LEN);if (p1=NULL)|(p2=NULL)printf (动态内存分配失败!n);getch();exit(0);printf (n请登记入住信息!n);printf (请选择房间号(%d%d):,MIN,MAX);scanf (%d,&number);if (numberMAX)printf (无此房间!);return;p1-room_number=number ;/在该房间没有旅客时,登记入住printf (name:t);scanf (%s,&p1-name);printf (
15、sex:t);scanf (%s,&p1-sex);printf (ID:t); scanf (%s,&p1-ID);printf (paid:t);scanf (%s,&p1-paid);printf (date(年月日空格隔开):);scanf (%d %d %d,&p1-inyear,&p1-inmonth,&p1-inday);p1-next=NULL ;if(head=NULL)/将输入信息保留到链表head=p1;p2=p1 ;elsep2-next=p1;p2=p1 ;fwrite(p2,LEN,1,fp);fclose (fp); /将链表信息保留到磁盘文件printf (n请
16、选择是否继续登记信息 (y/n):);/判定是否继续登记旅客信息scanf (%s,ch);if(strcmp(ch,y)!=0)printf (n登记旅客入住信息成功!);return(0);else regeist();return ;/登记完成后返回头链表指针void change() /李创:定义change函数实现换房功效int room_number ;int newroom_number ;struct Hotel *head, *pa,*L ;head=load();printf (n请输入需要换房房间序号:(%d%d):,MIN,MAX);scanf (%d,&room_nu
17、mber);if (room_numberMAX)printf (无此房间!);getch();return;pa= head-next; doif (pa)if(room_number=pa-room_number)printf (n);printf (roomnumber:t%d,pa-room_number);printf (n);printf (name:tt%s,pa-name);printf (n);printf (sex:tt%s,pa-sex);printf (n);printf (ID:tt%s,pa-ID);printf (n);printf (paid:tt%s,pa-p
18、aid);printf (n);printf (date:tt%d %d %d,pa-inyear,pa-inmonth,pa-inday);printf (n);printf (n请输入需要换到房间序号:(%d%d):,MIN,MAX);scanf (%d,&newroom_number);if (newroom_numberMAX)printf (无此房间!);getch();return;pa-room_number=newroom_number ;break ;pa = pa-next;elseprintf (n该房间还没有旅客入住!n);getch();return;while(1)
19、;fclose(fp);if(fp=fopen(resturant.txt,wb)=NULL)printf (无法打开文件!n);getch();exit(0);L=head-next;while(L)fwrite(L,LEN,1,fp);L=L-next ;fclose(fp);printf (n换房成功!);return;void fire() /王浩:定义fire函数实现退房功效char inname20 ;/用数组inname20来储存需要退房旅客namestruct Hotel *head, *qian,*pa,*L ;head=load();qian=(struct Hotel *
20、)malloc(LEN); /开辟新节点if (qian=NULL)printf (动态内存分配失败!n);/假如动态内存分配失败,返回失败信息getch();exit(0);printf (n请输入需要退房旅客姓名:);scanf (%s,inname);pa=head-next ;doif (pa)if(strcmp(inname,pa-name)=0)printf (n);printf (roomnumber:t%d,pa-room_number);printf (n);printf (name:tt%s,pa-name);printf (n);printf (sex:tt%s,pa-s
21、ex);printf (n);printf (ID:tt%s,pa-ID);printf (n);printf (paid:tt%s,pa-paid);printf (n);printf (date:tt%d %d %d,pa-inyear,pa-inmonth,pa-inday);printf (n); qian=head ;while(qian-next != pa) /找到需要查找节点前一个节点qian=qian-next ;if (pa-next=NULL)qian-next=NULL ;elseqian-next=pa-next ;break ;pa = pa-next;else printf (n没有查找到该旅客信息!n);getch();exit(0);while(1);L=head-next ; if(fp=fopen(resturant.txt,wb)=NULL)printf (无法打开文件!n);getch();exit(0);while(L)fwrite(L,LEN,1,fp);L=L-next ;fclose(fp);printf (n退房成功!);