#include <iostream> //#include"ticket.h" #include "string" using namespace std; #define Null 0 //乘客结构体 typedef struct Customer { char Name[10]; int Amount; //订票数 int Level; //舱位等级 int SeatNum; //座位号 char FlightNum[10]; //所定航班号 struct Customer *next; }Customer; //替补乘客结构体 typedef struct Replace { char Name[10]; int Amount; int Level; char FlightNum[10]; //所定航班号 struct Replace *next; }Replace; //Customer *Cusrear; //Replace *Reprear; typedef struct Flight //航线信息 {char Des[10]; //终点站名 char PlaneNum[10]; //航班号 char Week;//飞行周 int Ration;//乘员定额 int FreeTicket; //剩余票数 float Price[3];//舱位等级的价格 int ReplacePas;//候补乘客数 Customer *CustName;//已订票乘客名单 Replace *ReplName;//候补乘客名单 struct Flight *next;//指示下一航线节点 } Flight,*PFlight; //Flight *head;//定义航线头节点 //Flight *rear;//建立航线尾节点 void FlightInsert(Flight *head)//航班添加 { Flight *p; p=new Flight; cout<<"请输入终点站名:"<<endl; cin>>p->Des; //cout<<"请输入航班号:"<<endl; //cin>>p->FlightNum; cout<<"请输入飞机号:"<<endl; cin>>p->PlaneNum; cout<<"请输入飞行周:"<<endl; cin>>p->Week; cout<<"请输入乘员定额:"<<endl; cin>>p->Ration; p->FreeTicket=p->Ration; cout<<"请输入舱位等级的价格:"<<endl; cout<<"请输入头等舱价格:"<<endl; cin>>p->Price[0]; cout<<"请输入普通舱价格:"<<endl; cin>>p->Price[1]; cout<<"请输入经济舱价格:"<<endl; cin>>p->Price[2]; p->ReplName=new Replace; p->CustName=new Customer; p->CustName->next=Null; p->ReplName->next=Null; p->ReplacePas=0; p->next=head->next; head->next=p; //rear->next=p;// 利用尾指针便于航班的添加 //rear=p; //rear->next=Null; } void FlightSearch(Flight *head)//查询航班 { Flight *p,*q; char FlightNum[10]; int i=0; while (i!=1) {cout<<"请输入需要查询的航班号:"<<endl; cin>>FlightNum; p=head; while(p->next&&strcmp(p->next->PlaneNum,FlightNum)) { p=p->next; } q=p->next; if(q==Null) {cout<<"对不起不存在该航班"<<endl;} else {cout<<"航班号:"<<q->PlaneNum<<endl; cout<<"目的地:"<<q->Des<<endl; cout<<"飞行周:"<<q->Week<<endl; cout<<"乘员定额:"<<q->Ration<<endl; cout<<"剩余票数:"<<q->FreeTicket<<endl; cout<<"候补乘客数:"<<q->ReplacePas<<endl; cout<<"头等舱价格:"<<q->Price[0]<<endl; cout<<"普通舱价格:"<<q->Price[1]<<endl; cout<<"经济舱价格:"<<q->Price[0]<<endl;} cout<<"1、返回主菜单 2、继续"<<endl; cin>>i; } } void FlightRework(Flight *head)//修改航班信息 { int Customer_Number; Flight *p,*q; char FlightNum[10]; char i='0'; p=head; cout<<"请输入需要修改的航班号:"<<endl; cin>>FlightNum; while(p->next&&strcmp(p->next->PlaneNum,FlightNum)) {p=p->next;} q=p->next; if (q==Null) { cout<<"对不起不存在此航班"<<endl; } else { while(i!='8') {cout<<"********请输入要修改的信息********"<<endl; cout<<"1、航班号 "<<endl; cout<<"2、目的地 3、飞行周"<<endl; cout<<"4、乘员定额 5、头等舱价格"<<endl; cout<<"6、普通舱价格 7、经济舱价格"<<endl; cout<<"8、退出"<<endl; cout<<"********请输入要修改的信息********"<<endl; cin>>i; switch(i) {case '1':cout<<"请输入航班号:"<<endl; cin>>q->PlaneNum;break; case '2':cout<<"请输入目的地:"<<endl; cin>>q->Des;break; case '3':cout<<"请输入航班号飞行周:"<<endl; cin>>q->Week;break; case '4':cout<<"请输入乘员定额:"<<endl; Customer_Number=q->Ration-q->FreeTicket; cin>>q->Ration; q->FreeTicket=q->Ration-Customer_Number;break; case '5':cout<<"请输入头等舱价格:"<<endl; cin>>q->Price[0];break; case '6':cout<<"请输入普通舱价格:"<<endl; cin>>q->Price[1];break; case '7':cout<<"请输入经济舱价格:"<<endl; cin>>q->Price[2];break; case '8':break; default:cout<<"error\n";break; } } } } void FlightDelete(Flight *head) //利用表头指针定位要删除的航班信息 { Flight *p,*q; char FlightNum[10]; int i=0; while(i!=1) {cout<<"请输入需要删除的航班号:"<<endl; cin>>FlightNum; p=head; while(p->next&&strcmp(p->next->PlaneNum,FlightNum)) {p=p->next;} q=p->next; if(q!=Null) { // if(q->next==Null) // {rear=p;} p->next=p->next->next; delete q;} else {cout<<"你所要删除的航班不存在"<<endl;} cout<<"1、退出 2、继续"<<endl; cin>>i; } } void FlightBuyTicket(Flight *head)//订票 { int Ticket_Amount; void BuyTicket(Flight *,int); void Buyreplace(Flight *,int,int); Flight *p,*q; char Des[10]; int i=2; while(i!=1) {cout<<"请输入目的地:"<<endl; cin>>Des; p=head; while(p->next&&strcmp(p->next->Des,Des)) {p=p->next; } q=p->next; if (q==Null) {cout<<"对不起不存在此航班"<<endl;} else {while(i!=1) {cout<<"输入需要购买的票数"<<endl; cin>>Ticket_Amount; while(Ticket_Amount==0) { cout<<"请输入一个非零数"<<endl; cin>>Ticket_Amount; } if(Ticket_Amount<=q->FreeTicket) {BuyTicket(q,Ticket_Amount);}//买票 else {int n; cout<<"剩余票数小于订票数,是否需要列入候补名单?(1、是 2、否)"<<endl; cin>>n; Buyreplace(q,Ticket_Amount,n);//进入替补名单 } cout<<"1、返回菜单 2、继续"<<endl; cin>>i; } } } } void BuyTicket(Flight *q, int Ticket_Amount)//买票 {int n=Ticket_Amount; Customer *Cus2,*Cusrear; Cus2=new Customer; Cus2->SeatNum=q->Ration-q->FreeTicket+1; strcpy(Cus2->FlightNum,q->PlaneNum); Cus2->Amount=Ticket_Amount; cout<<"请输入姓名:"<<endl; cin>>Cus2->Name; cout<<"请输入舱位等级(1-3)"<<endl; cin>>Cus2->Level; cout<<"你的座位号为:"<<endl; for(int i=1;i<=Ticket_Amount;i++) { cout<<Cus2->SeatNum++<<" "; } cout<<endl; if(q->CustName->next==Null) { Cusrear=q->CustName; Cusrear->next=Cus2; Cusrear=Cus2; Cusrear->next=Null; } else{ Cusrear->next=Cus2; Cusrear=Cus2; Cusrear->next=Null; } q->FreeTicket-=Ticket_Amount; } void Buyreplace(Flight *q,int Ticket_Amount,int n)//进入替补队列 {Replace *Rep2,*Reprear; Rep2=new Replace; if(n==1) { q->ReplacePas+=Ticket_Amount; strcpy(Rep2->FlightNum,q->PlaneNum); Rep2->Amount=Ticket_Amount; cout<<"请输入姓名:"<<endl; cin>>Rep2->Name; cout<<"请输入舱位等级(1-3)"<<endl; cin>>Rep2->Level; if(q->ReplName->next==Null) {Reprear=q->ReplName; Reprear->next=Rep2; Reprear=Rep2; Reprear->next=Null; } else{ Reprear->next=Rep2; Reprear=Rep2; Reprear->next=Null; } } } void FlightCancelTicket(Flight *head)//退票 { //void BuyTicket(Flight,int); Flight *q,*p; Customer *h,*j,*Cusrear; Customer *Cus2; Replace *rep; char FlightNum[10]; char Customer_Name[10]; int Replace_Amount;//候补第一个人的订票数 int i=0; while(i!=1) { cout<<"请输入要退订的航班号:"<<endl; cin>>FlightNum; p=head; while(p->next&&strcmp(p->next->PlaneNum,FlightNum)) { p=p->next; } q=p->next; if(q==NULL) {cout<<"对不起不存在次航班"<<endl;} else { while(i!=2) {cout<<"请输入姓名:"<<endl; cin>>Customer_Name; h=q->CustName; while(h->next&&strcmp(h->next->Name,Customer_Name)) {h=h->next;} j=h->next; if(j==NULL) { cout<<"查无此人"<<endl; } else { if(j->next==NULL)//当删除最后一个节点 Cusrear=h; h->next=h->next->next; q->FreeTicket+=j->Amount; delete j; cout<<"删除成功!"<<endl; } if(q->ReplName->next!=NULL) { Replace_Amount=q->ReplName->next->Amount; if(Replace_Amount<=q->FreeTicket) { rep=q->ReplName->next; Cus2=new Customer; Cus2->SeatNum=q->Ration-q->FreeTicket+1; strcpy(Cus2->FlightNum,q->PlaneNum); strcpy(Cus2->Name,rep->Name); Cus2->Amount=rep->Amount; Cus2->Level=rep->Level; cout<<"乘客"<<rep->Name<<"已经成功买票"<<endl; cout<<"座位号:"; for(int i=1;i<=(rep->Amount);i++) { cout<<Cus2->SeatNum++<<" "; } cout<<endl; } if(q->CustName->next==Null) //把等候队列中的乘客加入到已经订票的乘客队列中 { Cusrear=q->CustName; Cusrear->next=Cus2; Cusrear=Cus2; Cusrear->next=Null; } else { Cusrear->next=Cus2; Cusrear=Cus2; Cusrear->next=Null; } q->FreeTicket-=rep->Amount; q->ReplName->next=q->ReplName->next->next; q->ReplacePas--; delete rep; } cout<<"2 退出姓名录入"<<endl; cin>>i; } } cout<<"1 返回主菜单"<<endl; cin>>i; } } void main() { Flight *head,*rear; head=rear=new Flight; head->next=Null; rear->next=Null; char i='0'; while(i!='7') { cout<<"********航空订票系统*********"<<endl; cout<<"1、增加航线 5、预订机票"<<endl; cout<<"2、查询航线 6、退订机票"<<endl; cout<<"3、修改航线 7、退出系统"<<endl; cout<<"4、删除航线 "<<endl; cout<<"*****************************"<<endl; cin>>i; switch(i) {case '1': FlightInsert(head );break; case '2': FlightSearch(head);break; case '3': FlightRework(head);break; case '4': FlightDelete(head);break; case '5': FlightBuyTicket(head);break; case '6': FlightCancelTicket(head);break; case '7':break; default:cout<<"error\n";break; } } }
- 粉丝: 1
- 资源: 2
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 10.php面试题_百度.doc
- 11.php面试题_腾讯.doc
- 08.NET面试题大全,包括微软、华为、中兴等大企业的面试真题.doc
- 07.Java面试宝典.doc
- 05.IT项目经理考题 V1-answer.doc
- 09.PHP经典面试题(基础型)附答案.doc
- 04.IT系统分析员考题 v1-answer.doc
- 13.华为瑞星360等公司软件测试工程师面试题.doc
- 14.软件测试经典面试题.doc
- 人力资源题库.doc
- 01.46家公司笔试面试题.doc
- 12.人事专员笔试题.doc
- 推广案例题.doc
- MD小组讨论题(十一).doc
- MD小组讨论题(六).doc
- MD小组讨论题(二).doc