C语言实现酒店管理系统

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
struct data{
char id[13];
char name[10];
char phone[12];
char intime[5];
char outtime[5];
char ordertime[5];
int vipoint;
int svipoint;
struct data *next;
};
int z=0;//计算节点长度
void main()
{
struct data *head=NULL;
struct data *s,*p,*ne,*cur,*pre,*q,*m;
int a,b,c=0,k[40],n,o,i,x,j;
char h[13],id[13];
time_t start ,end ;  
    double cost;
for(;a!=5;)
{
printf("****************************************\n");
printf("*             1.order room             *\n");
printf("*             2.check in               *\n");
printf("*             3.check out              *\n");
printf("*             4.see spare room         *\n");
printf("*             5.quit                   *\n");
printf("****************************************\n");
printf("choose the function \n");
scanf("%d",&a);
switch (a){
case 1:
printf("room type:1.standard 2.business 3.special discount room 4.hourly rate room\n");
scanf("%d",&b);
switch (b){
case 1:printf("────────────\n");
  printf("room number 101~110\n");
  printf("────────────\n");
  printf("price 100/day\n");
  printf("────────────\n");
  printf("clean level ★★★★★\n");
  printf("────────────\n");
  printf("offer breakfast \n");
  printf("────────────\n");
  printf("people number: ");
  scanf("%d",&b);
  for(i=0;i<b;i++)
  {
  z++;
  ne=(struct data*)malloc(sizeof(struct data));
  printf("enter the information:\n");
  printf("id: ");    scanf("%s",ne->id);
  printf("name: ");   scanf("%s",ne->name);
  printf("order time: ");   scanf("%s",ne->ordertime);
  printf("in time: ");    scanf("%s",ne->intime);
  ne->vipoint=0; ne->svipoint=0;
  if(head==NULL)
  head=ne;
  else
  {
  ne->next=head;
              head=ne;
  }
  }
  k[c]=rand()%4+101;
  printf(" room is %d\n",k[c]);
  c++;
  break; 
case 2:printf("────────────\n");
  printf("room number 111~120\n");
  printf("────────────\n");
  printf("price 180/day\n");
  printf("────────────\n");
  printf("clean level ★★★★★★★★\n");
  printf("────────────\n");
  printf("breakfast business remind function and shuttle service");
  printf("────────────────────────────\n");
  printf("people number: ");
  scanf("%d",&b);
  for(i=0;i<b;i++)
  {
  z++;
  ne=(struct data*)malloc(sizeof(struct data));
  printf("enter the information:\n");
  printf("id: ");    scanf("%s",ne->id);
  printf("name: ");   scanf("%s",ne->name);
  printf("norder time: ");   scanf("%s",ne->ordertime);
  printf("in time: ");    scanf("%s",ne->intime);
    ne->vipoint=0; ne->svipoint=0;
  if(head==NULL)
  head=ne;
  else
  {
  ne->next=head;
              head=ne;
  }
  }
  k[c]=rand()%4+201;
  printf("the room is %d\n",k[c]);
  c++;
  break;
   case 3:printf("────────────\n");
  printf("room number 121~130\n");
  printf("────────────\n");
  printf("price 20/hour\n");
  printf("────────────\n");
  printf("clean level ★★★★\n");
  printf("────────────\n");
  printf("people number: ");
  scanf("%d",&b);
  for(i=0;i<b;i++)
  {
  z++;
    ne=(struct data *)malloc(sizeof(struct data));
  printf("enter the information:\n");
  printf("id: ");    scanf("%s",ne->id);
  printf("name: ");   scanf("%s",ne->name);
  printf("order time: ");   scanf("%s",ne->ordertime);
  printf("in time: ");    scanf("%s",ne->intime);
    ne->vipoint=0; ne->svipoint=0;
  if(head==NULL)
  head=ne;
  else
  {
  ne->next=head;
              head=ne;
  }
  }
  k[c]=rand()%4+301;
  printf("the room is %d\n",k[c]);
  c++;
  break;
case 4:printf("────────────\n");
  printf("room number 130~140\n");
  printf("────────────\n");
  printf("price 80/day\n");
  printf("────────────\n");
  printf("clean level ★★★\n");
  printf("────────────\n");
  printf("offer breakfast ");
  printf("────────────\n");
  printf("people number: ");
  scanf("%d",&b);
  for(i=0;i<b;i++)
  {
  z++;
  ne=(struct data *)malloc(sizeof(struct data));
  printf("enter the information:\n");
  printf("id: ");    scanf("%s",ne->id);
  printf("name: ");   scanf("%s",ne->name);
  printf("order time: ");   scanf("%s",ne->ordertime);
  printf("in time: ");    scanf("%s",ne->intime);
    ne->vipoint=0; ne->svipoint=0;
  if(head==NULL)
  head=ne;
  else
  {
  ne->next=head;
              head=ne;
  }
  }
  k[c]=rand()%4+401;
  printf("the room is %d\n",k);
  break;
    default:printf("wrong!");
  break;
}
break;
case 2: printf("enter the id number:");//check in
scanf("%s",id);
s=head;
for(i=0;i<z;i++)
{
if(strcmp(id,s->id)==0)
{
printf("finish checking in\n");
time(&start);
}
else
printf("you must order first!\n");
s=s->next;
}
break;
case 3:printf("if VIP or SVIP or ORINATR(1,2,3) ");
scanf("%d",&o);
p=head;
if(o==1)
{
printf("enter the id number:  ");
scanf("%s",h);
printf("enter the room number: ");
scanf("%d",&n);
for(i=0;i<z;i++)
{
if(strcmp(p->id,h)==0)
{
printf("finish check out!\n");
k[i]=0;
time(&end);
cost=difftime(end,start);
x=(int)cost/60/60/24;
if(n/100==1)//according to room number to calculate the charge
{
if(x==0)
{
printf("the bill is 100\n");
p->vipoint=p->vipoint+1;
printf("the VIP point is %d\n",p->vipoint+1);
}
if(x!=0)
{
printf("the bill is %d",100*x);
p->vipoint=p->vipoint+1;
printf("the VIP point is %d\n",p->vipoint);
}
}
if(n/100==2)
{
if(x==0)
{
printf("the bill is 180\n");
p->vipoint=p->vipoint+1;
printf("the VIP point is %d\n",p->vipoint);
}
else
{
printf("the bill is %d",100*x);
p->vipoint=p->vipoint+1;
printf("the VIP point is %d\n",p->vipoint+1);
}
}
if(n/100==3)
{
if(x==0)
{
printf("the bill is 80\n");
p->vipoint=p->vipoint+1;
printf("the VIP point is %d\n",p->vipoint+1);
}
else
{
printf("the bill is %d",80*x);
p->vipoint=p->vipoint+1;
printf("the VIP point is %d\n",p->vipoint+1);
}
}
if(n/100==4)
{
if(cost/3600==0)
{
printf("the bill is 20\n");
p->vipoint=p->vipoint+1;
printf("the VIP point is %d\n",p->vipoint);
}
else
{
printf("the bill is %d\n",x*24*20);
p->vipoint=p->vipoint+1;
printf("the VIP point is %d\n",p->vipoint);
}
}
}
p=p->next;
}
}
if(o==2)
{
printf("enter room number: ");
scanf("%d",&n);
printf("enter the id number:  ");
scanf("%s",&h);
for(i=0;i<z;i++)
{
if(strcmp(h,p->id)==0)
{
printf("finish check out!\n");
time(&end);
k[i]=0;
cost=difftime(end,start);
x=(int)cost/60/60/24;
if(n/100==1)
{
if(x==0)
{
printf("the bill is 100\n");
p->svipoint=p->svipoint+1;
printf("the SVIP point is %d\n",p->svipoint);
}
else
{
printf("the bill is %d",80*x);
p->svipoint=p->svipoint+1;
printf("the SVIP point is %d\n",p->svipoint+1);
}
}
if(n/100==2)
{
if(x==0)
{
printf("the bill is 180\n");
p->svipoint=p->svipoint+1;
printf("the SVIP point is %d\n",p->svipoint);
}
else
{
printf("the bill is %d",100*x);
p->svipoint=p->svipoint+1;
printf("the SVIP point is %d\n",p->svipoint);
}

}
if(n/100==3)
{
if(x==0)
{
printf("the bill is 80\n");
   p->svipoint=p->svipoint+1;
printf("the SVIP point is %d\n",p->svipoint);
}
else
{
printf("the bill is %d",80*x);
p->svipoint=p->svipoint+1;
printf("the SVIP point is %d\n",p->svipoint);
}

}
if(n/100==4)
{
if((int)cost/60/60==0)
{
printf("the bill is 20\n");
p->svipoint=p->svipoint+1;
printf("the SVIP point is %d\n",p->svipoint);
}
else
{
printf("the bill is %d\n",cost/180);
p->svipoint=p->svipoint+1;
printf("the SVIP point is %d\n",p->svipoint);
}


}
}
p=p->next;
}
}
if(o==3)
{
printf("enter room number: ");
scanf("%d",&n);
printf("enter the id number:  ");
scanf("%s",h);
for(cur=head,pre=NULL;cur!=NULL&&strcmp(cur->id,h)!=0;pre=cur,cur=cur->next)
;
if(cur==NULL)

if(pre==NULL)
head=head->next;
else
pre->next=cur->next;
z--;
k[i]=0;
printf("finish check out!\n");
time(&end);
cost=difftime(end,start);
x=(int)cost/60/60/24;
if(n/100==1)
{
if(x==0)
{
printf("the bill is 100\n");

}
else
printf("the bill is %d",100*x);

}
if(n/100==2)
{
if(x==0)
{
printf("the bill is 180\n");
}
else
printf("the bill is %d",100*x);
}
if(n/100==3)
{
if(x==0)
{
printf("the bill is 80\n");
}
else
printf("the bill is %d",80*x);
}
if(n/100==4)
{
if(cost/3600==0)
{
printf("the bill is %d\n",x*24*20);
}
else
printf("the bill is %d\n",x*24*20);
}
}
break;
case 4:printf("the spare room is:  ");
  for(i=0;i<c;i++)
  {
  for(j=101;j<=140;j++)
  {
  if(k[i]!=j)
  printf("%d\t",j);
  }
  }
  printf("\n");
  break;
case 5:printf("ending!"); break;
default: printf(" ending !");
break;
}
}
q=head;
m=q;
for(i=0;i<z;i++)
{
free(m);
}
}

猜你喜欢

转载自blog.csdn.net/weixin_42526402/article/details/80783394