#include<stdio.h>
#include<stdlib.h>
#include<string.h>
enum noof
{
yes,
no
};
struct airplane
{
enum noof yno;
int zuowei;
char fname[20];
char lname[20];
};
void menu()
{
printf("To choose a function, empty its letter label:\n");
printf("(a) Show number of empty seats\n");
printf("(b) Show list of empty seats\n");
printf("(c) Show alphabetical list of seats\n");
printf("(d) Assign a customer to a seat assignment\n");
printf("(e) Delete a seat to a seat assignment\n");
printf("(f) Quit");
}
int * chongzhi(int n[])
{
for (int i = 1; i <= 12; i++)
n[i] = i;
return n;
}
char * s_gets(char * st, int n)
{
char * ret_val;
char * find;
ret_val = fgets(st, n, stdin);
if (ret_val)
{
find = strchr(st, '\n');
if (find)
* find = '\0';
else
while (getchar() != '\n')
continue;
}
return ret_val;
}
int main(void)
{
char ch;
struct airplane juren[13];
int n[13];
int temp;
chongzhi(n);
for (int i = 1; i <= 12; i++)
{
juren[i].zuowei = i;
juren[i].yno = no;
}
menu();
printf("请输入您的选择:\n");
while (scanf("%c", &ch) != NULL)
{
if (ch == 'q')
break;
if (ch == '\n')
continue;
switch(ch)
{
case 'a':
for (int i = 1; i <= 12; i++)
if (juren[i].yno == no)
printf("%d ", juren[i].zuowei);
printf("\n");
break;
case 'b':
for (int i = 1; i <= 12; i++)
if (juren[i].yno == no)
printf("%d号座位 ", juren[i].zuowei);
printf("\n");
break;
case 'c':
for (int i = 1; i < 12; i++)
for (int j = i + 1; j <= 12; j++)
if (juren[n[i]].fname[0] > juren[n[j]].fname[0])
{
temp = n[i];
n[i] = n[j];
n[j] = temp;
}
for (int i = 1; i <= 12; i++)
if (juren[n[i]].yno == yes)
printf("%d号: %s %s \n", juren[n[i]].zuowei, juren[n[i]].fname, juren[n[i]].lname);
chongzhi(n);
break;
case 'd':
printf("输入预定的座位号:\n");
scanf("%d", &temp);
while (getchar() != '\n')
continue;
if (juren[temp].yno == yes)
{
printf("输入号码已经有人预定.\n");
break;
}
else
{
juren[temp].yno = yes;
printf("输入您的姓:\n");
s_gets(juren[temp].fname, 20);
printf("输入您的名:\n");
s_gets(juren[temp].lname, 20);
}
break;
case 'e':
printf("输入取消的账号,您具有资格:\n");
scanf("%d", &temp);
juren[temp].yno = no;
break;
}
menu();
printf("请输入您的选择:\n");
}
printf("欢迎下次光临哦~\n");
return 0;
}
03-05
1434
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-21
1404
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)