#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN 20
#define MAX 12
#define S 3
struct fly{
char seat[S];
int reserve;
char fname[LEN];
char lname[LEN];
}seat_data[MAX]={{"A1", 0}, {"A2", 0}, {"A3", 0}, {"A4", 0}, {"A5",0}, {"A6", 0}, {"B1", 1,"BA","BA"},
{"B2", 1,"BB","BB"}, {"B3", 1,"BC","BC"}, {"B4", 1,"BD","BD"}, {"B5", 1,"BE","BE"}, {"B6", 1,"BF","BF"}};
int a(struct fly fly_data[],int n);
void b(struct fly fly_data[],int n);
void c(struct fly fly_data[],int n);
void d(struct fly fly_data[],int n);
void e(struct fly fly_data[],int n);
void menu(void);
int main(void)
{
char ch;
menu();
while (scanf("%c", &ch)!=EOF&&ch!='f')
{
while (getchar() != '\n')
continue;
switch (ch)
{
case 'a':
printf("empty seats:%d\n",a(seat_data,MAX));
break;
case 'b':
b(seat_data,MAX);
break;
case 'c':
c(seat_data,MAX);
break;
case 'd':
d(seat_data,MAX);
break;
case 'e':
e(seat_data,MAX);
break;
case 'f':
printf("bye\n");
break;
default:
printf("erro\n");
break;
}menu();
}
return 0;
}
void menu(void)
{
puts("To choose a function, enter its letter label:\n");
puts("a) Show number of empty seats\n");
puts("b) Show list of empty seats\n");
puts("c) Show alphabetical list of seats\n");
puts("d) Assign a customer to, a seat assignment\n");
puts("e) Delete a seat assignment\n");
puts("f) Quit\n");
}
int a(struct fly fly_data[],int n)
{
int count=0;
for(int i=0;i<n;i++)
{
if(fly_data[i].reserve==0)
count++;
}
return count;
}
void b(struct fly fly_data[],int n)
{
for(int i=0;i<n;i++)
{
if(fly_data[i].reserve==0)
printf("%s:空闲\n",fly_data[i].seat);
}
}
void c(struct fly fly_data[],int n)
{
for(int i=0;i<n;i++)
{
printf("%s |1预订,0未订: %d\n",fly_data[i].seat,fly_data[i].reserve);
}
}
void d(struct fly fly_data[],int n)
{
char seat[3];
b(fly_data,n);
puts("chose your seat,1 to quit:\n");
scanf("%s",&seat);
while (getchar() != '\n')
continue;
if(seat[0]='1')
return;
for(int i=0;i<n;i++)
if(strcmp(seat,fly_data[i].seat)==0)
{
fly_data[i].reserve=1;
puts("input your fname lname:\n");
scanf("%s %s",&fly_data[i].fname,&fly_data[i].lname);
while (getchar() != '\n')
continue;
}
puts("reserve succeed!:\n");
c(fly_data,n);
}
void e(struct fly fly_data[],int n)
{
char * seat[3];
char fname[LEN];
char lname[LEN];
int cancel=0;
for(int i=0;i<n;i++)
{
if(fly_data[i].reserve!=0)
printf("已预订的位置:%s\n",fly_data[i].seat);
}
puts("input your fname lname to delete your seat:\n");
while(cancel!=1)
{
scanf("%s %s",&fname,&lname);
while (getchar() != '\n')
continue;
for(int i=0;i<n;i++)
{
if (strcmp(lname,fly_data[i].lname)==0&&strcmp(fname,fly_data[i].fname)==0)
//名字对了才可以取消
{
fly_data[i].reserve=0;
printf("你的座位%s已取消",fly_data[i].seat);
cancel=1;
break;
}
else continue;
}
puts("1 to quit ,0 to rename:\n");
scanf("%d",&cancel);
while (getchar() != '\n')
continue;
if(cancel!=1)
puts("input your fname lname to delete your seat:\n");
}
puts("updated:\n");
c(fly_data,n);
}