1、C语言旅馆信息管理系统262020年4月19日文档仅供参考/*题目:旅店信息管理系统*小组成员:闫若琳 戴雨晨 马渊沐 张子飞 李闯 王浩 崔以博 孙浩浩 李春普 温健成*/#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
2、();void fire();struct Hotel *load();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 =(stru
3、ct Hotel *)malloc(LEN);if(pb=NULL)|(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 ()/崔以
4、博、孙浩浩 char choice ;do printf (nn-欢迎使用旅店信息管理系统-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; c
5、ase 5:regeist();break; case 6:change();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) prin
6、tf (无法打开文件!n);getch(); exit(0);ch=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请输入需要查看的房间序
7、号:(%d%d):,MIN,MAX);scanf (%d,&room_number);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:
8、tt%s,pa-ID);printf (n);printf (paid: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_num
9、berMAX)printf ( 无此房间!);return;continue ;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
10、 (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-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 ;/用数
11、组inname20来储存需要查询的旅客namestruct Hotel *head, *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:t
12、t%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);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
13、 printf (n没有查到该旅客的信息);return ;while(1);void 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 (
14、无法打开文件!n);getch();exit(0);head=NULL;p1=(struct 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 ;/在该房间没有旅客时,登记入住
15、printf (name:t);scanf (%s,&p1-name);printf (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,L
16、EN,1,fp);fclose (fp); /将链表信息保存到磁盘文件printf (n请选择是否继续登记信息 (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请输
17、入需要换房的房间序号:(%d%d):,MIN,MAX);scanf (%d,&room_number);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
18、: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);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;els
19、eprintf (n该房间还没有旅客入住!n);getch();return;while(1);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,
20、 *qian,*pa,*L ;head=load();qian=(struct Hotel *)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 (na
21、me: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-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退房成功!);