#include
#include
#include
using namespace std;
typedef struct Customer_regist{//已订票的客户
string name_end;//终点名称
string name_cust;//客户名称
string num_line;//航班号
string num_plane;//飞机号
string date;//飞行日期
int toatl;//票数
//Customer_regist *r;//表头
Customer_regist *next_Cust;//下一个客户
}Cust_reg, * L_Cust_reg;
typedef struct HouBu_node{//候补乘客
string name_end;//终点名称
string name_cust;//客户名称
string num_line;//航班号
string num_plane;//飞机号
string date;//飞行日期
int num_tickets;//需要的票数
HouBu_node *next_Cust_No_Reg;//下一个候补成员
}HoBuNode,* houbuNode;
typedef struct Customer_not_regist{
HouBu_node *front,*rear;
}HoBu;
typedef struct airline//航班
{
string name_end;//终点名称
string num_line;//航班号
string num_plane;//飞机号
string date;//飞行日期
int num_all;//成员总数
int num_rest;//剩余票数
}airline;
struct Airline{
airline *data;
L_Cust_reg h_cust;//订票成员
HouBu_node *front,*rear;//候补
int length;//航班数量
};
int static cust=1;
int static hou=1;
void init_cust(L_Cust_reg &l)
{
l=new Cust_reg[sizeof(Cust_reg)];
l->next_Cust=NULL;
}
//初始化候补乖客
void init_hobu(HoBu &hb)
{
hb.front=hb.rear=new HouBu_node;
hb.front->next_Cust_No_Reg=NULL;
}
//初始化航线表
void init_airline(Airline &al,L_Cust_reg &l,HoBu &hb)//录入航班表
{
al.data=new airline[max_size];
al.h_cust=l;
hb.rear=hb.front;
al.front=al.rear=hb.front;
al.length=0;
}
//向候补表中加入乘客
void insert_hobu(HoBu &hb,string name,string name_end,string num_line,string num_plane,string date,int num)
{
HouBu_node *p=new HouBu_node;
p->name_cust=name;
p->name_end=name_end;
p->num_line=num_line;
p->num_plane=num_plane;
p->date=date;
p->num_tickets=num;
p->next_Cust_No_Reg=NULL;
hb.rear->next_Cust_No_Reg=p;
hb.rear=p;
}
//输出候补乘员
void print_houbu(HoBu hb)
{
HouBu_node *p=new HouBu_node;
cout<
if(p=hb.rear)
{cout<
{
cout<
}
}
//出队
void out_houbu(HoBu &hb)
{if(hb.front==hb.rear)
cout<<"没有候补乘客!";
HouBu_node *p=new HouBu_node;
p=hb.front->next_Cust_No_Reg;
cout<
hb.front->next_Cust_No_Reg=p->next_Cust_No_Reg;
if(hb.rear==p)
hb.rear=hb.front;
}
void add_airline(Airline &al,L_Cust_reg &l,HoBu &hb){
cout<<"航班目的地:"<
cout<<"航班名称:"<
cout<<"飞机号:"<
cout<<"飞行日期"<
cout<<"成员总数:"<
al.data[al.length].num_rest=al.data[al.length].num_all;
++al.length;
}
//输出航班表
void print_airline(Airline al)
{
cout<
cout<
}
//向乖客表中添加乖客
void insert_cust(L_Cust_reg &l,int i,string name_end,string name_cust,string num_line,string num_plane,string date,int total)
{
L_Cust_reg s,p=l;
int j=0;
while(p&&j
if(!p&&j>i-1)
cout<<"ERROR!";
s=new Cust_reg[sizeof(Cust_reg)];
s->name_end=name_end;
s->name_cust=name_cust;
s->num_line=num_line;
s->num_plane=num_plane;
s->date=date;
s->toatl=total;
s->next_Cust=p->next_Cust;
p->next_Cust=s;
s->next_Cust=NULL;
p=p->next_Cust;
cout<<"订票成功!"<
//删除乘客表中信息
void del_cust(L_Cust_reg &l,int i)
{
L_Cust_reg p=l;
int j=0;
while(p->next_Cust&&j
if(!(p->next_Cust)||j>i-1)
{cout<<"ERROR!"<
L_Cust_reg q=new Cust_reg;
q=p->next_Cust;
p->next_Cust=q->next_Cust;
--cust;
cout<<"删除成功!欢迎再来!"<
//打印乘客信息
void print_cust(L_Cust_reg l)
{
L_Cust_reg p=l->next_Cust;
while(p)
{
cout<
}
}
//
//订票
void insert_airline(Airline &al,L_Cust_reg &l,HoBu &hb){
if(al.data[0].name_end!=""){
cout<<"本站提供以下站点的航班:"<
cout<<"请输入航班目的地:"<
for(int j=0;j
if(address==al.data[j].name_end)
{
cout<<"该航班的余票量:"<
cout<<"你的姓名:"<
cout<<"请输入你所需票量:"<
if(total<=al.data[j].num_rest&&al.data[j].num_rest>0)
{
cout<
print_cust(l);
++cust;
al.data[j].num_rest-=total;
print_airline(al);
break;
}
else
{
cout<<"你想等候吗?y(等)/n(不等)"<
cin>>c;
if(c=='y')
{
insert_hobu(hb,name_cust,al.data[j].name_end,al.data[j].num_line,al.data[j].num_plane,al.data[j].date,total);
cout<<"已排队中,请稍候!"<
else
{cout<<"谢谢光临!";}
}
}
else if(j==al.length&&address!=al.data[j].name_end)
{cout<<"无此航班!如想继续,请重新输入!"<
}
else
{
cout<<"ERROR!请先输入航班信息.";
}
}
//查询
void search(Airline al){
if(al.data[0].name_end!="")
{
cout<<"1.根据终点站名查询:"<<
"2.根据航班号查询: "<
string c;
cin>>choice;
switch(choice)
{case 1:
{
for(int j=0;j
cout<<"有以下站点";
cout<
cout<<"请输入终点站名:"<
for(int i=0;i
{
cout<<"航班目的地 "<<"航班号 "<<"飞机号 "<<"飞行日期 "<<"剩余票数 "<
else
{cout<<"无此航班!请重新输入!"<
}
};break;
case 2:
{
cout<<"有以下航班:"<
for(int i=0;i
{
cout<<"航班目的地 "<<"航班号 "<<"飞机号 "<<"飞行日期 "<<"剩余票数 "<
else
{cout<<"无此航班!请重新输入!"<
}
};break;
default:cout<<"输入错误!请重新输入!"<
}
else
{
cout<<"ERROR!请先录入航班信息!";
}
}
//退票
void del(Airline &al,L_Cust_reg &l,HoBu &hb)
{
cout<<"你需要根据以下选择来办理业务:"<<
"1.姓名"<<"2.日期"<<"3.航班号"<
string c;
L_Cust_reg p=l;
cin>>choice;
switch(choice){
case 1:
{
cout<<"请输入你的姓名:"<
while(p)
{
if(c==p->name_cust){
cout<<"姓名 "<<"航班目的地 "<<"航班号 "<<"飞机号 "<<"飞行日期 "<<"票数"<<" "<
cin>>k;
if(k==1)
{
for(int j=0;j
al.data[j].name_end=p->num_line;
al.data[j].num_rest+=p->toatl;
k=al.data[j].num_rest;
del_cust(l,i);
--cust;
bool f=hb.front!=hb.rear;
if(f){
if(k>hb.front->next_Cust_No_Reg->num_tickets)
{al.data[j].num_rest-=hb.front->next_Cust_No_Reg->num_tickets;
insert_cust(l,cust,hb.front->next_Cust_No_Reg->name_end,hb.front->next_Cust_No_Reg->name_cust,
hb.front->next_Cust_No_Reg->num_line,hb.front->next_Cust_No_Reg->num_plane,
hb.front->next_Cust_No_Reg->date,hb.front->next_Cust_No_Reg->num_tickets);
cout<<"候补乘客 :"<
}
}
else if(!f)
{cout<<"没有候补乘客!"<
}
break;
}
if(k==2)
{exit(0);}
}
else {p=p->next_Cust;}
if(!p)
{cout<<"你没有订票!";}
}
};break;
case 2:
{
cout<<"请输入你的日期:"<
while(p)
{
if(c==p->date){
cout<<"姓名 "<<"航班目的地 "<<"航班号 "<<"飞机号 "<<"飞行日期 "<<"票数"<<" "<
cin>>k;
if(k==1)
{
for(int j=0;j
al.data[j].name_end=p->num_line;
al.data[j].num_rest+=p->toatl;
k=al.data[j].num_rest;
del_cust(l,i);
--cust;
bool f=hb.front!=hb.rear;
if(f){
if(k>hb.front->next_Cust_No_Reg->num_tickets)
{al.data[j].num_rest-=hb.front->next_Cust_No_Reg->num_tickets;
insert_cust(l,cust,hb.front->next_Cust_No_Reg->name_end,hb.front->next_Cust_No_Reg->name_cust,
hb.front->next_Cust_No_Reg->num_line,hb.front->next_Cust_No_Reg->num_plane,
hb.front->next_Cust_No_Reg->date,hb.front->next_Cust_No_Reg->num_tickets);
cout<<"候补乘客 :"<
}
}
else if(!f)
{cout<<"没有候补乘客!"<
}
break;
}
if(k==2)
{exit(0);}
}
else {p=p->next_Cust;}
if(!p)
{cout<<"你没有订票!";}
}
};break;
case 3:
{
cout<<"请输入你的航班号:"<
while(p)
{
if(c==p->num_line){
cout<
cin>>k;
if(k==1)
{
for(int j=0;j
al.data[j].name_end=p->num_line;
al.data[j].num_rest+=p->toatl;
k=al.data[j].num_rest;
del_cust(l,i);
--cust;
bool f=hb.front!=hb.rear;
if(f){
if(k>hb.front->next_Cust_No_Reg->num_tickets)
{al.data[j].num_rest-=hb.front->next_Cust_No_Reg->num_tickets;
insert_cust(l,cust,hb.front->next_Cust_No_Reg->name_end,hb.front->next_Cust_No_Reg->name_cust,
hb.front->next_Cust_No_Reg->num_line,hb.front->next_Cust_No_Reg->num_plane,
hb.front->next_Cust_No_Reg->date,hb.front->next_Cust_No_Reg->num_tickets);
cout<<"候补乘客 :"<
}
}
else if(!f)
{cout<<"没有候补乘客!"<
}
break;
}
if(k==2)
{exit(0);}
}
else {p=p->next_Cust;}
if(!p)
{cout<<"你没有订票!";}
}
}
}
}
int main()
{
Airline al;
L_Cust_reg l;
HoBu hb;
init_cust(l);
init_hobu(hb);
init_airline(al,l,hb);
int t=1;char choice;
while(t==1)//进入菜单
{
system("cls");
cout<<"\n\n ****************欢迎使用航空订票系统**************\n\n";
cout<<" 请选择菜单\n\n";
cout<<" 1 航班录入\n\n";
cout<<" 2 查 询\n\n";
cout<<" 3 订 票\n\n";
cout<<" 4 退 票\n\n";
cout<<" 0 退 出\n\n";
cout<<"请选择: ";
cin>>choice;
switch(choice)
{
case '1':{//航班信息录入
system("cls");
add_airline(al,l,hb);//录入航班信息
print_airline(al);
system("pause");
};break;
case '2':{//查询
system("cls");
search(al);
system("pause");
};break;
case '3':{//订票
system("cls");
insert_airline(al,l,hb);
system("pause");
};break;
case '4':{//退票
system("cls");
del(al,l,hb);
system("pause");
};break;
case '0':{//退出本系统
system("cls");
char qr;
cout<<"确认退出(Y/N)?";//确认退出
cin>>qr;
if(qr=='Y'||qr=='y')
{
cout<<"\n=====>谢谢您的使用!\n";
cout<<"\n 〓正在退出系统...\n";
cout<<"\n ■■■■■■■■■■■■■■■■■■■■■■";
cout<<"\r";
for(int i=0;i<72;i++)
{
cout<<" ";
Sleep(60);
}
cout<
system("cls");
cout<<"已退出本系统!\n";
break;
}
else
{
break;
}
}
default:{
system("cls");
cout<<"输入有误\n";
system("pause");
}
}
}
return 0;
}
建议你把分数提高到500,兴许有人帮你写