数据结构课程设计(航空客运订票系统)_第1页
数据结构课程设计(航空客运订票系统)_第2页
数据结构课程设计(航空客运订票系统)_第3页
数据结构课程设计(航空客运订票系统)_第4页
数据结构课程设计(航空客运订票系统)_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、 (大学计算机科学与信息学院贡献)#include <iostream.h>#include <process.h>#include <string.h>#include <conio.h>#include <stdio.h>#include <iomanip.h>#define MAX 60#define NULL 0typedef struct Customer /*乘客信息*/ char Name8; /*/ int Amount; /*定票数*/ char Rank; /*舱位等级*/ int IDinfor; /

2、*个人信息*/ struct Customer *Next; /*指向下一乘客结点*/Customer;typedef struct Flight /*航线信息*/ char Des_Name10; /*终点站名*/ char Flight_No6; /*航班号*/ char Plane_No6; /*飞机号*/ int Week_Day; /*飞行周日*/ int Customer_Amount; /*乘员定额*/ int Free_Amount; /*剩余票数*/ int Price3; /*舱位等级的价格*/ Customer *CustName; /*该航班的已定票乘客*/ Custo

3、mer *ReplName; /*该航班的候补乘客*/ struct Flight *Next; /*指示下一航线结点*/Flight,*PFlight;int Customer_Count=0; /*所有航线的定票乘客总数*/Flight *Head; /*航线头指针*/Flight *p2; /*航线结点指针*/Customer *Custp1MAX; /*各条航线乘客结点指针*/Customer *Replp1MAX; /*各条航线候补结点指针*/int IsEmpty=1; /*是否有定票乘客*/int IsReplace=1; /*是否有候补乘客*/Customer *prior;

4、/*满足要求的定票乘客的前结点,以作删除操作*/int shouldsave=0;/*-询问是否继续的函数-*/char Continue() char answer; while(1) printf("nt 您是否想继续(Y/N)?"); scanf("%s",&answer); system("cls"); if(answer='y'|answer='Y') return 'y' else if(answer='n'|answer='N') r

5、eturn 'n' else printf("nt输入有误,请重新输入!"); /*-操作出错函数-*/void ErrorMess() printf("nt对不起,您的操作有误!");getch();/*-系统退出函数-*/int ExitSystem() char answer; printf("nt 您是否想要退出系统(Y/N)?"); scanf("%s",&answer); if(answer='y'|answer='Y') return 1; el

6、se return 0;/*-航线查找函数-*/*Find_Line()为重载函数*/int Find_Line(PFlight L,char *key)/*核对航线是否唯一*/ int flag=0; /*该标志位0表示未找到相关信息,反之即找到,以下标志位同理*/ Flight *p1; p1=L; /*赋航线首地址*/ if(p1=p2) /*首航线不作比较*/ return flag; while(p1!=p2&&p1!=NULL) /*本航班号不纳入比较围,否则会一直提示航线不唯一*/ if(strcmp(p1->Flight_No,key)=0) flag=1

7、; break; p1=p1->Next;/*指向下一航班结点*/ return flag;int Find_Line(PFlight L,char *key,PFlight &p2,int &Flight_No)/*航线查找函数*/ int flag=0; /*该标志位0表示未找到相关信息,反之即找到*/ Flight *p1; p1=L; /*赋航线首结点*/ while(p1!=NULL) if(strcmp(p1->Flight_No,key)=0)/*不包括当前航线*/ flag=1; p2=p1; break; p1=p1->Next; /*指向下

8、一航班结点*/ if(p1!=NULL) /*遇结束符不作统计围*/ Flight_No+; return flag;/*-航班查找函数-*/void Line_search() Flight *p1; p1=Head; char Desname50;/查询终点站航班关键字 if(Head=NULL) printf("nt没有到达您想要的终点站的航班!");getch(); return; printf("nt请输入终点站名:"); scanf("%s",Desname); printf("nt您所查询的航班的信息:n&qu

9、ot;); printf("n_n"); while(p1!=NULL) if(strcmp(p1->Des_Name,Desname)=0) printf("Des_Name Flight_No Plane_No Week_Day Cust_Num Free_Num 1_Price 2_Price 3_Pricen"); printf("n%-9s%-10s%-9s%-9d%-9d%-9d%-8d%-8d%-8d",p1->Des_Name,p1->Flight_No,p1->Plane_No,p1->

10、Week_Day, p1->Customer_Amount,p1->Free_Amount,p1->Price0,p1->Price1,p1->Price2); p1=p1->Next; printf("n_n"); Continue(); /*-航线添加函数-*/void Line_Add() Flight *p1; /*建立临时航线结点*/ while(1) if(Head=NULL)/*航线为空*/ p1=p2=new Flight; /*建立首个航线*/ Head=p2; else p1=new Flight; /*建立航线结点*

11、/ p2->Next=p1; /*前一航线结点指向当前航班结点*/ p2=p1; /*保留当前航班结点地址*/ printf("nt添加新的航线!n"); printf("nt请输入终点站名:"); scanf("%s",&p2->Des_Name); while(1) /*数据合法性检验*/ printf("nt请输入唯一的航班号:"); scanf("%s",&p2->Flight_No); if(Find_Line(Head,p2->Flight_N

12、o) /*存在航班号*/ printf("nt航班号已经存在!n"); else break; printf("nt请输入飞机号:"); scanf("%s",&p2->Plane_No); while(1) printf("nt请输入航班日期(请输入17):"); scanf("%d",&p2->Week_Day); if(p2->Week_Day<1|p2->Week_Day>7) printf("nt输入日期有误,请重新输入!n

13、"); else break; printf("nt请输入座位数量:"); scanf("%d",&p2->Customer_Amount); printf("nt请输入头等舱的价钱:"); scanf("%d",&p2->Price0); printf("nt请输入二等舱的价钱:"); scanf("%d",&p2->Price1); printf("nt请输入三等舱的价钱:"); scanf(&quo

14、t;%d",&p2->Price2); p2->Free_Amount=p2->Customer_Amount; /*剩余票数与乘员定额一样*/ p2->CustName=NULL; /*该航线定票乘客头指针为空*/ p2->ReplName=NULL; /*初始候补为空 */shouldsave=1; if(Continue()='n') p2->Next=NULL; /*航线的下一结点为空*/ return; /*-航线是否为空函数-*/int Empty_Flight() if(Head=NULL) system(&q

15、uot;cls"); printf("nt对不起,航线不存在,按任意键返回!"); getch(); return 1; else return 0;/*-航线查看函数-*/void Line_See() system("cls"); Flight *p1; p1=Head; if(Empty_Flight() /*航班线为空*/ return; printf("nnt航班信息:n"); printf("n_n"); printf("Des_Name Flight_No Plane_No Wee

16、k_Day Cust_Num Free_Num 1_Price 2_Price 3_Pricen"); while(p1!=NULL) printf("n%-9s%-10s%-9s%-9d%-9d%-9d%-8d%-8d%-8d",p1->Des_Name,p1->Flight_No,p1->Plane_No,p1->Week_Day,p1->Customer_Amount,p1->Free_Amount,p1->Price0,p1->Price1,p1->Price2); p1=p1->Next; pr

17、intf("n_n"); printf("nt按任意键返回!n"); getch();/*-航线管理菜单-*/ void LinemanageMenu() char c; system("cls");while(1) printf("ntt航线管理菜单:"); printf("n_nn"); printf("t1.添加新的航线n"); printf("t2.查询航线n"); printf("t3.查看航线n"); printf(&quo

18、t;t4.返回主菜单n"); printf("n_n"); printf("t请选择您想要的服务:"); scanf("%s",&c); switch(c) case '1':Line_Add();break;case '2':Line_search();break; case '3':Line_See();break; case '4':return; /*-订票办理函数-*/void bookingMenu() int Ticket_Count,ID

19、infor,i,flag=0; int Flight_No=0; /*记录满足条件的航线的定票结点*/ Flight *p1; /*记下满足条件的航线结点地址*/ Customer *p2; /*临时性定票乘员结点*/ Customer *p3; /*临时性候补乘员结点*/ char answer7; /*用户输入的航班数据*/ char temp; char c; int tag=0; /*候补乘客标志位*/ int IsRepl=0; /*是否执行候补操作标志位*/ if(Empty_Flight() /*航班线为空*/ return; while(1) printf("nt现在

20、您可以订票!"); flag=0; /*标志位清零以重新作出判断*/ Flight_No=0; tag=0; printf("nt请输入航线号:"); scanf("%s",&answer); if(Find_Line(Head,answer,p1,Flight_No) /*调用航线查找函数,若存在则进行以下操作*/ while(1) /*数据合法性检验*/ printf("nt请输入您想要订购的票的数量:"); scanf("%d",&Ticket_Count); if(Ticket_C

21、ount=0) printf("nt请再次输入飞机号:n"); getch(); else break; if(p1->Free_Amount>=Ticket_Count) Customer_Count+; /*定票乘客总数增1*/ flag=1; /*表明进入了订票实际操作*/ IsRepl=1; /*定票量满足,无需进入候补操作*/ if(p1->CustName=NULL) /*首个定票乘客,并记录相关属性*/ Custp1Flight_No=p2=new Customer; /*建立该航线的首位乘客结点*/ p1->CustName=Cust

22、p1Flight_No; else /*建立该航线的后续乘客结点*/ p2=new Customer; Custp1Flight_No->Next=p2; Custp1Flight_No=p2; IsEmpty=0; /*定票乘员不为空*/ Custp1Flight_No->Amount=Ticket_Count; /*订票数*/ IDinfor=p1->Customer_Amount-p1->Free_Amount+1; /*算出座位号*/ Custp1Flight_No->IDinfor=IDinfor; /*赋座位号*/ p1->Free_Amount

23、-=Ticket_Count; /*减去定票数*/ printf("nt请输入您的:"); scanf("%s",&Custp1Flight_No->Name); while(1) /*数据合法性检验*/ printf("nt请输入舱位等级:"); scanf("%s",&Custp1Flight_No->Rank); if(!(Custp1Flight_No->Rank>='1'&&Custp1Flight_No->Rank<=&

24、#39;3') printf("nt输入有误,请重新输入!"); getch(); else break; printf("nt请输入您的ID信息:");scanf("%d",&Custp1Flight_No->IDinfor); if(Ticket_Count<10) /*为显示规整,作相应处理*/ printf("nt"); else printf("nt"); printf("nt恭喜您订票成功!n"); for(i=1;i<=Tick

25、et_Count;i+) /*打印座位号*/ printf("nt您所预定的座位号是%d",IDinfor+); if(i%10=0) printf("nt"); printf("n"); /*满足定票数*/ else if(p1->Free_Amount=0) printf("nt对不起,票已售完!n"); IsRepl=0; else printf("nt对不起,当前没有多余的票!n"); IsRepl=0; if(!IsRepl) printf("nt您是否想成为候补乘客(

26、Y/N)?"); scanf("%s",&temp); if(temp='y'|temp='Y')/*以下为候补操作*/ if(p1->ReplName=NULL) Replp1Flight_No=p3=new Customer; /*建立该航线的首位候补乘客结点*/ p1->ReplName=Replp1Flight_No; else p3=new Customer; Replp1Flight_No->Next=p3; Replp1Flight_No=p3; IsReplace=0; /*候补乘客不为空*

27、/ tag=1; /*已选择列入候补乘客*/ Replp1Flight_No->Amount=Ticket_Count; printf("nt请输入您的:"); scanf("%s",&Replp1Flight_No->Name); Replp1Flight_No->IDinfor=IDinfor; /*候补乘客的座位*/ Replp1Flight_No->Amount=Ticket_Count; /*候补乘客的订票数*/ while(1) /*数据合法性检验*/ printf("nt请输入舱位等级:"

28、); scanf("%s",&Replp1Flight_No->Rank); printf("nt请输入您的ID信息:"); scanf("%d",&Replp1Flight_No->IDinfor); if(!(Replp1Flight_No->Rank>='1'&&Replp1Flight_No->Rank<='3') printf("nt输入有误,请重新输入."); getch(); else break; p

29、rintf("nt没有剩余座位!n");/*候补乘客无座提示*/shouldsave=1; /*进入候补 */ /*票数满足*/ /*航线存在*/ else printf("nt对不起,航线不存在!n");/*航线不存在*/ if(flag) /*此处不作处理,则会地址溢出*/ Custp1Flight_No->Next=NULL;/*末位定票乘客的指针置空*/ if(tag) Replp1Flight_No->Next=NULL;/*末位候补乘客的指针置空*/ printf("nt您已经成功排入候补订票队列中!n");

30、printf("nt是否退出菜单?:(y/n)"); scanf("%s",&c); if(c='y') return; /*while*/ /*-订票乘客信息-*/void Display_Reserve() system("cls"); Flight *p1; Customer *p2; p1=Head; if(Empty_Flight() return; printf("nt订票乘客信息"); if(IsEmpty) printf("nt对不起,没有订票乘客信息!n"

31、;); getch(); return; printf("n_n"); printf("Name Flight_No Plane_No Tic_Amount Des_Name Rank_No IDn"); while(p1!=NULL) if(p1->CustName!=NULL) p2=p1->CustName; while(p2!=NULL) printf("n%-8s%-10s%-9s%-11d%-9s%-9c%-9d",p2->Name,p1->Flight_No,p1->Plane_No,p2-

32、>Amount,p1->Des_Name,p2->Rank,p2->IDinfor); if(p1->Free_Amount>=1) printf("nnt还有多余的票!n"); else printf("nnt票已售完!n"); p2=p2->Next; p1=p1->Next; printf("nn_n"); printf("nt按任意键返回!"); getch(); return;/*-候补乘客信息-*/void Display_Replace() system

33、("cls"); Flight *p1; Customer *p2; p1=Head; if(Empty_Flight() return; printf("nt候补乘客信息!"); if(IsReplace) printf("nt对不起,没有候补乘客!n"); getch(); return; printf("n_n"); printf("Name Flight_No Plane_No Tic_Amount Des_Name Rank_No IDn"); while(p1!=NULL) if(p

34、1->ReplName!=NULL) p2=p1->ReplName; while(p2!=NULL) printf("n%-8s%-10s%-9s%-11d%-9s%-9c%-9d",p2->Name,p1->Flight_No,p1->Plane_No,p2->Amount,p1->Des_Name,p2->Rank,p2->IDinfor); if( p1->Free_Amount>=1) printf("nt还有多余的票!n"); else printf("nt票已售完!

35、n"); p2=p2->Next; p1=p1->Next; printf("nn_n"); printf("nt按任意键返回!"); getch(); return;/*-退票办理函数-*/void RefundticketMenu() int Flight_No=0,flag=0; /*记录满足条件的航线的定票结点*/ Flight *p1; /*记下满足条件的航线结点地址*/ Customer *p2,*p4; /*临时性定票乘员结点*/ Customer *p3,*p5; /*临时性候补乘员结点*/ char answer7

36、,name7; /*用户输入的航班数据*/ int tag=0; /*若第二乘客满足条件,则它的首地址会发生冲突,注意此处*/ int IDinfor; /*记录座位号*/ if(Empty_Flight() /*航班线为空*/ return; printf("nt现在开始进行退票手续"); if(IsEmpty) printf("nt对不起,乘客不存在!"); getch(); return; while(1) flag=0; tag=0; Flight_No=0; printf("nt请输入航线:"); scanf("%

37、s",&answer); if(Find_Line(Head,answer,p1,Flight_No) /*航线存在*/ p2=p1->CustName; /*指向该航线的乘客的首地址 */ printf("nt请输入您的:"); scanf("%s",&name); if(p2=NULL) /*该航线无定票乘客*/ printf("nt对不起,乘客不存在!."); if(Continue()='n')/*是否继续操作*/ return; else while(p2!=NULL)/*查找

38、有无此乘客名*/ if(strcmp(p2->Name,name)=0)/*此外括号不能省略,否则功能会转变*/ if(p2=p1->CustName) /*若为首位乘客满足*/ prior=p1->CustName; /*记录指针*/ IDinfor=p2->IDinfor; flag=1; break; else if(p2->Next!=NULL)/*记录满足航线的的前结点地址 */ if(strcmp(p2->Next->Name,name)=0) tag=1; /*特别注意此处*/ prior=p2; /*记录满足定乘客的前一地址,以作删除操

39、作*/ IDinfor=p2->Next->IDinfor; flag=1; break; p2=p2->Next; /*指向下一乘客结点*/shouldsave=1; /*while */ if(!flag) printf("nt对不起,乘客不存在!n"); /*存在该航线*/ else printf("nt对不起,航线不存在!n"); if(flag) if(prior=p1->CustName&&!tag) /*首结点满足条件且一个乘客,则该航线定票乘客置空*/ if(prior->Next=NULL)

40、 /*仅一乘客,头指针置空*/ p1->Free_Amount+=prior->Amount; p1->CustName=NULL; else p1->Free_Amount+=prior->Next->Amount; p1->CustName=prior->Next; /*指向下一乘客结点*/ else p1->Free_Amount+=prior->Next->Amount; prior->Next=prior->Next->Next; /*删除操作*/ Customer_Count-; if(Custom

41、er_Count=0) IsEmpty=1;shouldsave=1; if(flag)/*存在退票操作*/ p3=p1->ReplName; while(p3!=NULL) if(p3->Amount<=p1->Free_Amount)/*候补乘客的定票数小于或等于剩余票数*/ printf("nt候补乘客已经存在!n"); p4=Custp1Flight_No->Next=new Customer; p4->Next=NULL; IsEmpty=0; if(p1->CustName=NULL) p1->CustName=p

42、4; strcpy(p4->Name,p3->Name); p4->Rank=p3->Rank; p4->Amount=p3->Amount; p4->IDinfor=IDinfor; p1->Free_Amount-=p3->Amount; /*减去相应的票数*/ Customer_Count+; if(p3->Next=NULL) /*无候补乘客 */ IsReplace=1; if(p1->ReplName=p3) if(p1->ReplName->Next=NULL) p1->ReplName=NULL;/*删除*/ else p1->ReplName=p3->Next; else p5->Next=p3->Next->Next; break; if(p3->Next!=NULL) if(p3->Next->Amount<=p1->Free_Amount)

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论