#include <stdio.h>
#define SIZE 12
void print ();
void show_nullnum (struct plane *a);
void show_listnum (struct plane *b);
void show_alphabeticallist (struct plane *c);
void assign_num (struct plane *d);
void delete_num (struct plane *e);
struct plane {
int num;
int sf;
char name[20];
};
int main (void)
{
char q;
struct plane planes[SIZE] =
{
{0, 1, " "},
{1, 1, " "},
{2, 1, " "},
{3, 1, " "},
{4, 1, " "},
{5, 1, " "},
{6, 1, " "},
{7, 1, " "},
{8, 1, " "},
{9, 1, " "},
{10, 1, " "},
{11, 1, " "},
};
print ();
scanf ("%c", &q);
while (q != 'f')
{
while ( q < 'a' || q > 'f') //!!!!!!!!!!这个地方要是|| 运算符
{
printf ("输入错误\n");
print ();
fflush(stdin); /*!!!!!!!!!!清空缓冲区,也可以使用rewind(stdin);*/
scanf ("%c", &q);
}
switch (q)
{
case 'a':
show_nullnum (planes);
break;
case 'b':
show_listnum (planes);
break;
case 'c':
show_alphabeticallist (planes);
break;
case 'd':
assign_num (planes);
break;
case 'e':
delete_num (planes);
break;
case 'f':
break;
}
if (q != 'f')
{
print ();
fflush(stdin); /*!!!!!!!!!!!清空缓冲区,也可以使用rewind(stdin);*/
scanf ("%c", &q);
}
}
return 0;
}
void print ()
{
printf ("选择一个函数,输入字母标签\n");
printf ("a) 显示的空座位号码\n");
printf ("b) 显示的空座位表\n");
printf ("c) 显示的席位按字母顺序排列的列表\n");
printf ("d) 分配一个客户一个座位\n");
printf ("e) 删除一个座位\n");
printf ("f) 退出\n");
}
void show_nullnum (struct plane *a)
{
int i, sum;
for (i = 0, sum = 0; i < SIZE; i++)
{
if (a[i].sf)
sum++;
}
printf ("一共还有%d个空位\n", sum);
}
void show_listnum (struct plane *b)
{
int i;
for (i = 0; i < SIZE; i++)
{
if (b[i].sf)
printf ("座号:%d", b[i].num);
}
}
void show_alphabeticallist (struct plane *c)
{
int i;
for (i = 0; i < SIZE; i++)
{
printf ("座号:%d ", c[i].num);
if (c[i].sf)
printf ("空座\n");
else
printf ("%s %s\n", c[i].name);
}
}
void assign_num (struct plane *d)
{
int i;
printf ("请输入需要的座位:");
scanf ("%d", &i);
if (d[i].sf)
{
printf ("请输入姓名:");
scanf ("%s", &d[i].name);
d[i].sf = 0;
}
else
printf ("此座位已被预定\n");
}
void delete_num (struct plane *e)
{
int i;
printf ("请输入需要退订的座位:");
scanf ("%d", &i);
if (e[i].sf)
printf ("此座位无预定");
else
e[i].sf = 1;
}
//程序改了,现在可以了