void statistic() /*统计*/
{
char choice='x';
char roomstatus[10];
unsigned done=0;
unsigned roomcnt=0;
unsigned emptycnt=0;
unsigned bookedcnt=0;
unsigned checkedincnt=0;
unsigned customercnt=0;
struct Rooms *ROOMCUSOR=NULL;
struct Roomp *REMPTYS=NULL;
struct Roomp *RBOOKEDS=NULL;
struct Roomp *RCHECKEDINS=NULL;
struct Roomp *RPCUSOR=NULL;
struct Customers *CUSTOMERHEAD=NULL;
struct Customers *CUSTOMERCUSOR=NULL;
struct Customers *CBOOKEDS=NULL;
struct Customers *CCHECKEDINS=NULL;
struct Customers *ALLCUSTOMERS=NULL;
struct Customers *CPCUSOR=NULL;
struct Rooms *HEAD=ROOM;
struct Rooms *CUSOR=HEAD;
struct Roomp *REMPTYSCUSOR=NULL;
struct Roomp *RBOOKEDSCUSOR=NULL;
struct Roomp *RCHECKEDINSCUSOR=NULL;
struct Customers *CBOOKEDSCUSOR=NULL;
struct Customers *CCHECKEDINSCUSOR=NULL;
struct Customers *ALLCUSTOMERSCUSOR=NULL;
cls();
printf("\t\t =============================================\n");
printf("\t\t * 统 计 选 单 *\n");
printf("\t\t *===========================================*\n");
printf("\t\t * 1.客房概况 6.顾客概况 *\n");
printf("\t\t * *\n");
printf("\t\t * 2.所有客房 7.所有顾客 *\n");
printf("\t\t * *\n");
printf("\t\t * 3.空闲客房 8.订房顾客 *\n");
printf("\t\t * *\n");
printf("\t\t * 4.预订客房 9.入住顾客 *\n");
printf("\t\t * *\n");
printf("\t\t * 5.入住客房 0.退出统计 *\n");
printf("\t\t =============================================\n");
while(1)
{
printf("\n请选择统计项目:");
choice=getchar();
flushstdin();
switch(choice)
{
case '1':
{
printf("\n正在统计...\n");
if(!done)
{
CUSOR=ROOM;
while(CUSOR!=NULL)
{
if(CUSOR->theroom.Sing==EMPTY)
{
if(REMPTYS==NULL)
{
REMPTYSCUSOR=malloc(sizeof(struct Roomp));
REMPTYSCUSOR->theroom=&(CUSOR->theroom);
REMPTYS=REMPTYSCUSOR;
REMPTYS->before=NULL;
REMPTYS->next=NULL;
}
else
{
REMPTYSCUSOR->next=malloc(sizeof(struct Roomp));
REMPTYSCUSOR->next->before=REMPTYSCUSOR;
REMPTYSCUSOR=REMPTYSCUSOR->next;
REMPTYSCUSOR->theroom=&CUSOR->theroom;
REMPTYSCUSOR->next=NULL;
}
emptycnt++;
roomcnt++;
}
if(CUSOR->theroom.Sing==BOOKED)
{
if(RBOOKEDS==NULL)
{
RBOOKEDSCUSOR=malloc(sizeof(struct Roomp));
RBOOKEDSCUSOR->theroom=&(CUSOR->theroom);
RBOOKEDS=RBOOKEDSCUSOR;
RBOOKEDS->before=NULL;
RBOOKEDS->next=NULL;
}
else
{
RBOOKEDSCUSOR->next=malloc(sizeof(struct Roomp));
RBOOKEDSCUSOR->next->before=RBOOKEDSCUSOR;
RBOOKEDSCUSOR=RBOOKEDSCUSOR->next;
RBOOKEDSCUSOR->theroom=&(CUSOR->theroom);
RBOOKEDSCUSOR->next=NULL;
}
if(CBOOKEDS==NULL)
{
CBOOKEDSCUSOR=malloc(sizeof(struct Customers));
CBOOKEDSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
CBOOKEDS=CBOOKEDSCUSOR;
CBOOKEDS->before=NULL;
CBOOKEDS->next=NULL;
}
else
{
CBOOKEDSCUSOR->next=malloc(sizeof(struct Customers));
CBOOKEDSCUSOR->next->before=CBOOKEDSCUSOR;
CBOOKEDSCUSOR=CBOOKEDSCUSOR->next;
CBOOKEDSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
CBOOKEDSCUSOR->next=NULL;
}
if(ALLCUSTOMERS==NULL)
{
ALLCUSTOMERSCUSOR=malloc(sizeof(struct Customers));
ALLCUSTOMERSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
ALLCUSTOMERS=ALLCUSTOMERSCUSOR;
ALLCUSTOMERS->before=NULL;
ALLCUSTOMERS->next=NULL;
}
else
{
ALLCUSTOMERSCUSOR->next=malloc(sizeof(struct Customers));
ALLCUSTOMERSCUSOR->next->before=ALLCUSTOMERSCUSOR;
ALLCUSTOMERSCUSOR=ALLCUSTOMERSCUSOR->next;
ALLCUSTOMERSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
ALLCUSTOMERSCUSOR->next=NULL;
}
bookedcnt++;
roomcnt++;
customercnt++;
}
if(CUSOR->theroom.Sing==CHECKEDIN)
{
if(RCHECKEDINS==NULL)
{
RCHECKEDINSCUSOR=malloc(sizeof(struct Roomp));
RCHECKEDINSCUSOR->theroom=&CUSOR->theroom;
RCHECKEDINS=RCHECKEDINSCUSOR;
RCHECKEDINS->before=NULL;
RCHECKEDINS->next=NULL;
}
else
{
RCHECKEDINSCUSOR->next=malloc(sizeof(struct Roomp));
RCHECKEDINSCUSOR->next->before=RCHECKEDINSCUSOR;
RCHECKEDINSCUSOR=RCHECKEDINSCUSOR->next;
RCHECKEDINSCUSOR->theroom=&CUSOR->theroom;
RCHECKEDINSCUSOR->next=NULL;
}
if(CCHECKEDINS==NULL)
{
CCHECKEDINSCUSOR=malloc(sizeof(struct Customers));
CCHECKEDINSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
CCHECKEDINS=CCHECKEDINSCUSOR;
CCHECKEDINS->before=NULL;
CCHECKEDINS->next=NULL;
}
else
{
CCHECKEDINSCUSOR->next=malloc(sizeof(struct Customers));
CCHECKEDINSCUSOR->next->before=CCHECKEDINSCUSOR;
CCHECKEDINSCUSOR=CCHECKEDINSCUSOR->next;
CCHECKEDINSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
CCHECKEDINSCUSOR->next=NULL;
}
if(ALLCUSTOMERS==NULL)
{
ALLCUSTOMERSCUSOR=malloc(sizeof(struct Customers));
ALLCUSTOMERSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
ALLCUSTOMERS=ALLCUSTOMERSCUSOR;
ALLCUSTOMERS->before=NULL;
ALLCUSTOMERS->next=NULL;
}
else
{
ALLCUSTOMERSCUSOR->next=malloc(sizeof(struct Customers));
ALLCUSTOMERSCUSOR->next->before=ALLCUSTOMERSCUSOR;
ALLCUSTOMERSCUSOR=ALLCUSTOMERSCUSOR->next;
ALLCUSTOMERSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
ALLCUSTOMERSCUSOR->next=NULL;
}
checkedincnt++;
roomcnt++;
customercnt++;
}
CUSOR=CUSOR->next;
}
done=1;
}
printf("\t\t\t ======客房概况统计======\n");
printf("\t\t =============================================\n");
printf("\t\t 总 数 空 闲 预 订 入 住 \n");
printf("\t\t =============================================\n");
printf("\t\t %3u %3u %3u %3u \n",roomcnt,emptycnt,bookedcnt,checkedincnt);
printf("\t\t =============================================\n");
break;
}
case '2':
{
printf("\n正在统计...\n");
if(!done)
{
CUSOR=ROOM;
while(CUSOR!=NULL)
{
if(CUSOR->theroom.Sing==EMPTY)
{
if(REMPTYS==NULL)
{
REMPTYSCUSOR=malloc(sizeof(struct Roomp));
REMPTYSCUSOR->theroom=&(CUSOR->theroom);
REMPTYS=REMPTYSCUSOR;
REMPTYS->before=NULL;
REMPTYS->next=NULL;
}
else
{
REMPTYSCUSOR->next=malloc(sizeof(struct Roomp));
REMPTYSCUSOR->next->before=REMPTYSCUSOR;
REMPTYSCUSOR=REMPTYSCUSOR->next;
REMPTYSCUSOR->theroom=&CUSOR->theroom;
REMPTYSCUSOR->next=NULL;
}
emptycnt++;
roomcnt++;
}
if(CUSOR->theroom.Sing==BOOKED)
{
if(RBOOKEDS==NULL)
{
RBOOKEDSCUSOR=malloc(sizeof(struct Roomp));
RBOOKEDSCUSOR->theroom=&(CUSOR->theroom);
RBOOKEDS=RBOOKEDSCUSOR;
RBOOKEDS->before=NULL;
RBOOKEDS->next=NULL;
}
else
{
RBOOKEDSCUSOR->next=malloc(sizeof(struct Roomp));
RBOOKEDSCUSOR->next->before=RBOOKEDSCUSOR;
RBOOKEDSCUSOR=RBOOKEDSCUSOR->next;
RBOOKEDSCUSOR->theroom=&(CUSOR->theroom);
RBOOKEDSCUSOR->next=NULL;
}
if(CBOOKEDS==NULL)
{
CBOOKEDSCUSOR=malloc(sizeof(struct Customers));
CBOOKEDSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
CBOOKEDS=CBOOKEDSCUSOR;
CBOOKEDS->before=NULL;
CBOOKEDS->next=NULL;
}
else
{
CBOOKEDSCUSOR->next=malloc(sizeof(struct Customers));
CBOOKEDSCUSOR->next->before=CBOOKEDSCUSOR;
CBOOKEDSCUSOR=CBOOKEDSCUSOR->next;
CBOOKEDSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
CBOOKEDSCUSOR->next=NULL;
}
if(ALLCUSTOMERS==NULL)
{
ALLCUSTOMERSCUSOR=malloc(sizeof(struct Customers));
ALLCUSTOMERSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
ALLCUSTOMERS=ALLCUSTOMERSCUSOR;
ALLCUSTOMERS->before=NULL;
ALLCUSTOMERS->next=NULL;
}
else
{
ALLCUSTOMERSCUSOR->next=malloc(sizeof(struct Customers));
ALLCUSTOMERSCUSOR->next->before=ALLCUSTOMERSCUSOR;
ALLCUSTOMERSCUSOR=ALLCUSTOMERSCUSOR->next;
ALLCUSTOMERSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
ALLCUSTOMERSCUSOR->next=NULL;
}
bookedcnt++;
roomcnt++;
customercnt++;
}
if(CUSOR->theroom.Sing==CHECKEDIN)
{
if(RCHECKEDINS==NULL)
{
RCHECKEDINSCUSOR=malloc(sizeof(struct Roomp));
RCHECKEDINSCUSOR->theroom=&CUSOR->theroom;
RCHECKEDINS=RCHECKEDINSCUSOR;
RCHECKEDINS->before=NULL;
RCHECKEDINS->next=NULL;
}
else
{
RCHECKEDINSCUSOR->next=malloc(sizeof(struct Roomp));
RCHECKEDINSCUSOR->next->before=RCHECKEDINSCUSOR;
RCHECKEDINSCUSOR=RCHECKEDINSCUSOR->next;
RCHECKEDINSCUSOR->theroom=&CUSOR->theroom;
RCHECKEDINSCUSOR->next=NULL;
}
if(CCHECKEDINS==NULL)
{
CCHECKEDINSCUSOR=malloc(sizeof(struct Customers));
CCHECKEDINSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
CCHECKEDINS=CCHECKEDINSCUSOR;
CCHECKEDINS->before=NULL;
CCHECKEDINS->next=NULL;
}
else
{
CCHECKEDINSCUSOR->next=malloc(sizeof(struct Customers));
CCHECKEDINSCUSOR->next->before=CCHECKEDINSCUSOR;
CCHECKEDINSCUSOR=CCHECKEDINSCUSOR->next;
CCHECKEDINSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
CCHECKEDINSCUSOR->next=NULL;
}
if(ALLCUSTOMERS==NULL)
{
ALLCUSTOMERSCUSOR=malloc(sizeof(struct Customers));
ALLCUSTOMERSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
ALLCUSTOMERS=ALLCUSTOMERSCUSOR;
ALLCUSTOMERS->before=NULL;
ALLCUSTOMERS->next=NULL;
}
else
{
ALLCUSTOMERSCUSOR->next=malloc(sizeof(struct Customers));
ALLCUSTOMERSCUSOR->next->before=ALLCUSTOMERSCUSOR;
ALLCUSTOMERSCUSOR=ALLCUSTOMERSCUSOR->next;
ALLCUSTOMERSCUSOR->thecustomer=&(CUSOR->theroom.Client_list);
ALLCUSTOMERSCUSOR->next=NULL;
}
checkedincnt++;
roomcnt++;
customercnt++;
}
CUSOR=CUSOR->next;
}
done=1;
}
ROOMCUSOR=ROOM;
printf("\t\t==============================================\n");
printf("\t\t 房间号 房间电话 房间价格 房间状态 \n");
printf("\t\t*--------------------------------------------*\n");
while(ROOMCUSOR!=NULL)
{
switch(ROOMCUSOR->theroom.Sing)
{
case EMPTY: {strcpy(roomstatus,"空 闲");break;}
case BOOKED: {strcpy(roomstatus,"已预订");break;}
default: {strcpy(roomstatus,"已入住");break;}
}
printf("\t\t %4s %7s %4u %3s \n",ROOMCUSOR->theroom.Room_ID,ROOMCUSOR->theroom.Tel,ROOMCUSOR->theroom.Price,roomstatus);
printf("\t\t*--------------------------------------------*\n");
ROOMCUSOR=ROOMCUSOR->next;
}
printf("\t\t 合计: %3u 间。\n",roomcnt);
printf("\t\t==============================================\n");
ROOMCUSOR=NULL;
break;
}