#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!=NULL)
{
p=p->next1;
printf("%10d%10s%10s%10d%10d\n",p->fnum,p->pnum,p->end,p->vote,p->more);
}
printf("\n");
}
void print_consumer(linklist2 &l2)//输出顾客列表
{
linklist2 q;
printf("输出顾客信息列表:\n\n");
printf(" 姓名 航班号 座位号\n");
q=l2;
while(q->next2!=NULL)
{
q=q->next2;
printf("%10s%10d%10d\n",q->name,q->fnumber,q->dnumber);
}
printf("\n");
}
void print1()//头界面
{
printf(" 计算机科学与技术1001班 数据结构 课程设计\n");
printf(" 航空订票系统\n");;
printf(" 设计人:温春琰\n");
}
void print2()//主界面
{
printf("*------------------------------*\n");
printf("*-----航空订票系统选择菜单-----*\n");
printf("* 订票--------0 *\n");
printf("* 退票--------1 *\n");
printf("* 查询--------2 *\n");
printf("* 修改航线----3 *\n");
printf("* 退出--------4 *\n");
printf("*------------------------------*\n");
}
void print3()//子界面
{
printf("*------------------------------*\n");
printf("*---------航线信息修改---------*\n");
printf("* 增加航班号--------0 *\n");
printf("* 删除航班号--------1 *\n");
printf("* 修改密码----------2 *\n");
printf("* 查询航班信息------3 *\n");
printf("* 退出航线修改------4 *\n");
printf("*------------------------------*\n");
}
void change_key(int &e)//改变密码
{
printf("请输入新的密码(全部为数字):");
scanf("%d",&e);
printf("新的密码设置成功!新密码为:%d\n",e);
}
int change_dnumber(linklist1 &l1,linklist2 &l2,int fnumber,int dnumber)//座位号分配
{
linklist1 p;
p=l1;
while(p->fnum!=fnumber)
{
p=p->next1;
}
dnumber=p->vote-p->more+1;
--p->more;
printf("订票成功!\n你的座位号为:%d\n",dnumber);
return dnumber;
}
void change_more(linklist1 &l1,int fnumber)//订票时剩余座位的变化
{
linklist1 p=l1;
while(fnumber!=l1->fnum)
{
p=p->next1;
}
--p->more;
}
int select1(linklist1 &l1,int &e)//子选择 航线修改
{
print3();
int key,fnum,vote,more;
char pnum[20],end[20];
printf("请选择:");
scanf("%d",&key);
switch(key)
{
case 0:
printf("请输入你要增加的航班号:");
scanf("%d",&fnum);
printf("请输入你要增加的飞机号:");
scanf("%s",&pnum);
printf("请输入你要增加的目的地:");
scanf("%s",&end);
printf("请输入你要增加的座位数:");
scanf("%d",&vote);
more=vote;
create_plane(l1,fnum,pnum,end,vote,more);
printf("添加航班%d成功!\n",fnum);
return 1;
case 1:
delete_plane(l1);
return 1;
case 2:
change_key(e);
printf("e = ",e);
return 1;
case 3:
print_plane(l1);
return 1;
case 4:
return 0;
}
return 0;
}
int select2(linklist1 &L1,linklist2 &L2,int &e)//主选择
{
int key,i;
int fnumber,dnumber;
print2();
char name[20];
printf("请选择:");
scanf("%d",&key);
switch(key)
{
case 0:
printf("请输入你要订的航班号:");
scanf("%d",&fnumber);
printf("请输入你的姓字:");
scanf("%s",&name);
dnumber=change_dnumber (L1,L2,fnumber,dnumber);
create_consumer(L2,name,fnumber,dnumber);
return 1;
case 1:
delete_consumer(L1,L2);
return 1;
case 2:
print_plane(L1);
print_consumer(L2);
return 1;
case 3:
printf("请输入密码:");
scanf("%d",&i);
while(i!=e)
{
printf("密码输入错误!\n");
printf("请重新输入密码:");
scanf("%d",&i);
}
for(;select1(L1,e););
return 1;
case 4:
printf("*--------------结束-------------*\n");
return 0;
}
return 0;
}
int main()//主函数
{
int e = 123;
print1();
linklist1 L1;
linklist2 L2;
L1=(linklist1)malloc(sizeof(plane));
L2=(linklist2)malloc(sizeof(consumer));
L1->next1=NULL;
L2->next2=NULL;
init_plane(L1);
init_consumer(L2);
for(;select2(L1,L2,e););
return 0;
}
本文来源:https://www.2haoxitong.net/k/doc/bda83222ccbff121dd368310.html
文档为doc格式