#include
#include
#include
#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];
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);
void copy_seat_data(struct fly dest[], const struct fly src[], int count) ;
void handle_menu(struct fly seat_data[],int n);
int main(void)
{
char ch;
int flight=0;
struct fly seat_102[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"}};
struct fly seat_311[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"}};
struct fly seat_444[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"}};
struct fly seat_519[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"}};
starting:puts("choose our flight (102,311,444,519) or 1 to quit:");
while (scanf("%d",&flight)==1&&flight!=102&&flight!=311&&flight!=444&&flight!=519&&flight!=1)
{
while (getchar() != '\n')
continue;
puts("wrong num :(102,311,444,519,1)");
}
while (getchar() != '\n')
continue;
switch (flight)
{
case 102:
copy_seat_data(seat_data, seat_102, MAX);
break;
case 311:
copy_seat_data(seat_data, seat_311, MAX);
break;
case 444:
copy_seat_data(seat_data, seat_444, MAX);
break;
case 519:
copy_seat_data(seat_data, seat_519, MAX);
break;
case 1:
exit(1);
break;
default:
puts("wrong num):");
break;
}
handle_menu(seat_data,MAX);
goto starting;
}
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
if(fly_data[i].reserve==0)
count++;
}
return count;
}
void b(struct fly fly_data[],int n)
{
for(int i=0;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
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
{
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
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
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);
}
void copy_seat_data(struct fly dest[], const struct fly src[], int count)
{
for (int i = 0; i < count; ++i)
{
strcpy(dest[i].seat, src[i].seat);
dest[i].reserve = src[i].reserve;
strcpy(dest[i].fname, src[i].fname);
strcpy(dest[i].lname, src[i].lname);
}
}
void handle_menu(struct fly seat_data[],int n)
{
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,n));
break;
case 'b':
b(seat_data,n);
break;
case 'c':
c(seat_data,n);
break;
case 'd':
d(seat_data,n);
break;
case 'e':
e(seat_data,n);
break;
case 'f':
printf("bye\n");
break;
default:
printf("erro\n");
break;
}
menu();
}
}