#include"stdio.h"
#include"stdlib.h"
struct home
{char roomNO[20];
char name[20];
char sex[10];
char person[10];
char time[10];
char contain[10];
char money[10];
struct home *next;
struct home *prior;
}list_entry;
struct home *start;
struct home *last;
void search1();
main()
{
int b;
struct home *info;
start=0;
for(;;){
switch(menu_select()){
case 1:enter();break;
case 2:alter();break;
case 3:search();break;
case 4:cost();break;
case 5:delete();break;
case 6:tongji();break;
case 7:tuichu();
}
}
}
menu_select()
{ int c;
printf("\t\t=========================================================\n");
printf("\t\t=========================================================\n");
printf("\t\t==== 宾馆客房管理系统 ====\n");
printf("\t\t==== 请选择功能 ====\n");
printf("\t\t==== 1 输入客房情况 ====\n");
printf("\t\t==== 2 修改客房情况 ====\n");
printf("\t\t==== 3 查询客房情况 ====\n");
printf("\t\t==== 4 客房费用 ====\n");
printf("\t\t==== 5 删除指定客房 ====\n");
printf("\t\t==== 6 统计客房情况 ====\n");
printf("\t\t==== 7 退出系统 ====\n");
printf("\t\t=========================================================\n");
printf("\t\t=========================================================\n");
do{
printf(" 请按数字选择\n");
scanf("%d",&c);getchar();
}while(c<0||c>10);
return c;
}
enter()
{struct home *info,*dls_store(); char s[10]; char a[10]="have";
for(;;)
{
info=malloc(sizeof(list_entry));
if(info==0)
{printf(" 内存已用完\n");
return;
}
inputs(" \t客房号码 \n",info->nember,10);
if(!info->nember[0]) break;
inputs(" \t能住的人数\n",info->contain,10);
inputs(" \t有人输入have无人输入null\n",info->person,10);
if(!strcmp(a,info->person)){
inputs("\t姓名:\n",info->name,10);
inputs("\t姓别:\n",info->sex,10);
inputs("\t住入时间:\n",info->time,10);
}
inputs(" \t有人时输入时间无人输入\n",info->time,10);
inputs(" \t输入客房费用\n",info->money,10);
start=dls_store(info,start);
}
}
inputs(prompt,s,count)
char *prompt;
char *s;
int count;
{
char p[255];
do{
printf(prompt);
gets(p);
if(strlen(p)>count)
printf(" 太长啦\n ");
}while(strlen(p)>count);
strcpy(s,p);
}
struct home *dls_store(i,top)
struct home *i,*top;
{
static struct home *last=0;
struct home *old,*p;
if(last==0){
i->next=0;
i->prior=0;
last=i;
return i;
}
p=top;
old=0;
while(p){
if(strcmp(p->nember,i->nember)<0){
old=p;
p=p->next;
}
else{
if(p->prior){
p->prior->next=i;
i->next=p;
p->prior=i;
return top;
}
i->next=p;
i->prior=0;
p->prior=i;
return i;
}
} old->next=i;
i->next=0;
i->prior=old;
last=i;
return start;
}
alter()
{
struct home *info,*find();
char roomNO[20]; char a[10]="have"; char c[10]="null";
int b;
printf(" \t如想查看客房情况输入1\n");
printf(" \t想修改输入2\n");
printf(" \t不想修改输入3\n");
scanf("%d",&b);
if(b==1)search();
if(b==2){
printf(" \t请输入要客房号码\n");
scanf("%s",nember);getchar();
if(!(info=find(nember)))printf("\t没找到\n");
else
{
display(info);printf("\t下面是修改项目\n");
if(!strcmp(a,info->person))
inputs("\t请输入null:\n",info->person,10);
if(!strcmp(c,info->person)){
inputs("\t请输入名字\n",info->name,10);
inputs("\t请输入性别\n",info->sex,10);
inputs("\t请输入时间\n",info->time,10);
}
}
}
if(b==3) return;
}
struct home *find(nember)
char *nember;
{ struct home *info;
info=start;
while(info){
if(!strcmp(nember,info->nember)) return info;
info=info->next;
}
printf(" \t没找到\n");
return (NULL);
} display(info)
struct home *info;
{ char a[10]="have";
printf("\t客房号码: %s\n",info->nember);
printf("\t能住人数: %s\n",info->contain);
printf("\t无人住时显示null有人住时显示have:%s\n",info->person);
if(!strcmp(a,info->person)){
printf("\t名字%s\n",info->name);
printf("\t性别%s\n",info->sex);
printf("\t时间%s\n",info->time);}
printf("\t客房每天费用: %s\n",info->money);
printf("\n");
}
search()
{
int b;
printf(" \t查询只定客房输入1\n");
printf(" \t查询已住客房输入2\n");
printf(" \t查询未住客房输入3\n");
printf(" \t返回主菜单请输入4\n");
do{
scanf("%d",&b);
switch(b){
case 1: search1();break;
case 2: search2();break;
case 3: search3();break;
case 4: return;
}
}while(b<1||b>5);
} | |
void search1()
{ char nember[10];
struct home *info,*find();
printf(" \t输入房号码\n");
scanf("%s",nember); getchar();
if(!(info=find(nember))) printf(" \t没找到\n");
else display(info);
}
search2()
{struct home *info;
char a[10]="have";
info=start;
while(info){
if(!strcmp(info->person,a))
display(info);
printf("\n");
info=info->next;
}
}
search3()
{struct home *info;
char b[10]="null";
info=start;
while(info){
if(!strcmp(b,info->person))
display(info);
printf(" \n ");
info=info->next;
}
}
save()
{
register int t,size;
struct home *info;
char *p;
FILE *fp;
if((fp=fopen("mlist","wb"))==0){
printf(" \t文件打不开\n");
exit(0);
}
printf("\t 正存入内存\n");
size=sizeof(list_entry);
info=start;
while(info){
p=(char*)info;
for(t=0;t<size;++t)
putc(*p++,fp);
info=info->next;
}
putc(EOF,fp);
fclose(fp);
printf("\t已存完\n");
}
cost()
{
char nember[10];
struct home *info;
printf(" \t请输入客房号码\n");
gets(nember);
if(!(info=find(nember)))printf("\t没找到\n");
else{ display(info);
printf(" \t如果退房时间在12:00后按一天时间计算\n");
}
}
delete()
{struct home *info,*find();
char nember[10];
printf(" \t请输入指定客房号码\n");
scanf("%s",&nember);
info=find(nember);
if(info){
if(start==info){
start=info->next;
if(start)
start->prior=0;}
else
last=0;
}
else
{
info->prior->next=info->next;
if(info!=last)
info->next->prior=info->prior;
else
last=info->prior;
}
free(info);
}
tuichu()
{
int c;
printf("\t建议您最好存盘如果存盘输入1不存输入2\n");
scanf("%d",&c);
if(c==1) save();
if(c==2){
printf("\t谢谢您使用本系统:\n");
exit(0);
}
} tongji()
{
struct home *info;
char a[10]="have";
char b[10]="null";
int c,count=0;
printf("\t统计未住客房号码输入1已住客房号码输入2:\n");
scanf("%d",&c);
if(c==1){
info=start;
while(info)
{
if(!strcmp(a,info->person)) {
printf("\客房号码 %s \n",info->nember);
count++; }
info=info->next;
}
printf("\t共有未住客房%d个\n",count); }
if(c==2)
{ info=start;
while(info)
{ if(!strcmp(b,info->person))
{ printf("\t客房号码 %s \n",info->nember);
count++;}
info=info->next;
} printf("\t共有已住客房%d\n",count);
}
}
|