#include
#include
#include
#include
#define ok 1
#define error 0
#define overflow -2
int select2();
typedef struct plane
{
int fnum;//航班号
char pnum[20];//飞机号
char end[20];//终点
int vote;//票数
int more;//余票
struct plane *next1;
}plane,*linklist1;
typedef struct consumer
{
char name[20];
int fnumber;//航班号
int dnumber;//座位号
struct consumer *next2;
}consumer,*linklist2;
void create_plane(linklist1 &l1,int fnum,char pnum[20],char end[20],int vote,int more)//创建航班列表
{
linklist1 p,q;
q=l1;
p=(linklist1)malloc(sizeof(plane));
p->next1=q->next1;
q->next1=p;
p->fnum=fnum;
strcpy(p->pnum,pnum);
strcpy(p->end,end);
p->vote=vote;
p->more=more;
}
void create_consumer(linklist2 &l2,char name[20],int fnumber,int dnumber)//创建顾客列表
{
linklist2 p,q;
q=l2;
p=(linklist2)malloc(sizeof(consumer));
p->next2=q->next2;
q->next2=p;
strcpy(p->name,name);
p->fnumber=fnumber;
p->dnumber=dnumber;
}
void init_plane(linklist1 &l1)//初始化航空列表
{
create_plane(l1,1101,"plane001","xian",100,51);
create_plane(l1,1102,"plane002","shanghai",100,71);
create_plane(l1,1103,"plane003","beijing",100,30);
}
void init_consumer(linklist2 &l2)//初始化顾客列表
{
create_consumer(l2,"lier",1101,1);
create_consumer(l2,"lisan",1102,5);
create_consumer(l2,"lisi",1103,10);
}
void delete_plane(linklist1 &l1)//取消航班
{
int a;
printf("输入需要取消的航班:");
scanf("%d",&a);
linklist1 p,q;
q=p=l1;
while(a!=q->fnum)
{
p=q;
q=q->next1;
}
p->next1=q->next1;
printf("删除%d成功!\n",q->fnum);
free(q);
}
void delete_consumer(linklist1 &l1, linklist2 &l2)//取消订票
{
char a[100];
printf("请输入你的姓名:");
scanf("%s",&a);
linklist2 p,q;
linklist1 s;
s=l1;
q=p=l2;
while(strcmp(a,q->name)!=0)
{
p=q;
q=q->next2;
s=s->next1;
}
++s->more;
p->next2=q->next2;
printf("顾客 %s退票成功!\n",q->name);
free(q);
}
void print_plane(linklist1 &l1)//航空列表的输出
{
linklist1 p;
printf("输出航班信息列表:\n\n");
printf(" 航班 飞机号 终点站 总票数 剩余票数\n");
p = l1;
while(p->next1!=NUL