數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)(航空客運(yùn)訂票系統(tǒng))_第1頁(yè)
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)(航空客運(yùn)訂票系統(tǒng))_第2頁(yè)
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)(航空客運(yùn)訂票系統(tǒng))_第3頁(yè)
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)(航空客運(yùn)訂票系統(tǒng))_第4頁(yè)
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)(航空客運(yùn)訂票系統(tǒng))_第5頁(yè)
已閱讀5頁(yè),還剩13頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、 (大學(xué)計(jì)算機(jī)科學(xué)與信息學(xué)院貢獻(xiàn))#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; /*定票數(shù)*/ char Rank; /*艙位等級(jí)*/ int IDinfor; /

2、*個(gè)人信息*/ struct Customer *Next; /*指向下一乘客結(jié)點(diǎn)*/Customer;typedef struct Flight /*航線信息*/ char Des_Name10; /*終點(diǎn)站名*/ char Flight_No6; /*航班號(hào)*/ char Plane_No6; /*飛機(jī)號(hào)*/ int Week_Day; /*飛行周日*/ int Customer_Amount; /*乘員定額*/ int Free_Amount; /*剩余票數(shù)*/ int Price3; /*艙位等級(jí)的價(jià)格*/ Customer *CustName; /*該航班的已定票乘客*/ Custo

3、mer *ReplName; /*該航班的候補(bǔ)乘客*/ struct Flight *Next; /*指示下一航線結(jié)點(diǎn)*/Flight,*PFlight;int Customer_Count=0; /*所有航線的定票乘客總數(shù)*/Flight *Head; /*航線頭指針*/Flight *p2; /*航線結(jié)點(diǎn)指針*/Customer *Custp1MAX; /*各條航線乘客結(jié)點(diǎn)指針*/Customer *Replp1MAX; /*各條航線候補(bǔ)結(jié)點(diǎn)指針*/int IsEmpty=1; /*是否有定票乘客*/int IsReplace=1; /*是否有候補(bǔ)乘客*/Customer *prior;

4、/*滿足要求的定票乘客的前結(jié)點(diǎn),以作刪除操作*/int shouldsave=0;/*-詢問(wèn)是否繼續(xù)的函數(shù)-*/char Continue() char answer; while(1) printf("nt 您是否想繼續(xù)(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輸入有誤,請(qǐng)重新輸入!"); /*-操作出錯(cuò)函數(shù)-*/void ErrorMess() printf("nt對(duì)不起,您的操作有誤!");getch();/*-系統(tǒng)退出函數(shù)-*/int ExitSystem() char answer; printf("nt 您是否想要退出系統(tǒng)(Y/N)?"); scanf("%s",&answer); if(answer='y'|answer='Y') return 1; el

6、se return 0;/*-航線查找函數(shù)-*/*Find_Line()為重載函數(shù)*/int Find_Line(PFlight L,char *key)/*核對(duì)航線是否唯一*/ int flag=0; /*該標(biāo)志位0表示未找到相關(guān)信息,反之即找到,以下標(biāo)志位同理*/ Flight *p1; p1=L; /*賦航線首地址*/ if(p1=p2) /*首航線不作比較*/ return flag; while(p1!=p2&&p1!=NULL) /*本航班號(hào)不納入比較圍,否則會(huì)一直提示航線不唯一*/ if(strcmp(p1->Flight_No,key)=0) flag=1

7、; break; p1=p1->Next;/*指向下一航班結(jié)點(diǎn)*/ return flag;int Find_Line(PFlight L,char *key,PFlight &p2,int &Flight_No)/*航線查找函數(shù)*/ int flag=0; /*該標(biāo)志位0表示未找到相關(guān)信息,反之即找到*/ Flight *p1; p1=L; /*賦航線首結(jié)點(diǎn)*/ while(p1!=NULL) if(strcmp(p1->Flight_No,key)=0)/*不包括當(dāng)前航線*/ flag=1; p2=p1; break; p1=p1->Next; /*指向下

8、一航班結(jié)點(diǎn)*/ if(p1!=NULL) /*遇結(jié)束符不作統(tǒng)計(jì)圍*/ Flight_No+; return flag;/*-航班查找函數(shù)-*/void Line_search() Flight *p1; p1=Head; char Desname50;/查詢終點(diǎn)站航班關(guān)鍵字 if(Head=NULL) printf("nt沒(méi)有到達(dá)您想要的終點(diǎn)站的航班!");getch(); return; printf("nt請(qǐng)輸入終點(diǎn)站名:"); 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(); /*-航線添加函數(shù)-*/void Line_Add() Flight *p1; /*建立臨時(shí)航線結(jié)點(diǎn)*/ while(1) if(Head=NULL)/*航線為空*/ p1=p2=new Flight; /*建立首個(gè)航線*/ Head=p2; else p1=new Flight; /*建立航線結(jié)點(diǎn)*

11、/ p2->Next=p1; /*前一航線結(jié)點(diǎn)指向當(dāng)前航班結(jié)點(diǎn)*/ p2=p1; /*保留當(dāng)前航班結(jié)點(diǎn)地址*/ printf("nt添加新的航線!n"); printf("nt請(qǐng)輸入終點(diǎn)站名:"); scanf("%s",&p2->Des_Name); while(1) /*數(shù)據(jù)合法性檢驗(yàn)*/ printf("nt請(qǐng)輸入唯一的航班號(hào):"); scanf("%s",&p2->Flight_No); if(Find_Line(Head,p2->Flight_N

12、o) /*存在航班號(hào)*/ printf("nt航班號(hào)已經(jīng)存在!n"); else break; printf("nt請(qǐng)輸入飛機(jī)號(hào):"); scanf("%s",&p2->Plane_No); while(1) printf("nt請(qǐng)輸入航班日期(請(qǐng)輸入17):"); scanf("%d",&p2->Week_Day); if(p2->Week_Day<1|p2->Week_Day>7) printf("nt輸入日期有誤,請(qǐng)重新輸入!n

13、"); else break; printf("nt請(qǐng)輸入座位數(shù)量:"); scanf("%d",&p2->Customer_Amount); printf("nt請(qǐng)輸入頭等艙的價(jià)錢:"); scanf("%d",&p2->Price0); printf("nt請(qǐng)輸入二等艙的價(jià)錢:"); scanf("%d",&p2->Price1); printf("nt請(qǐng)輸入三等艙的價(jià)錢:"); scanf(&quo

14、t;%d",&p2->Price2); p2->Free_Amount=p2->Customer_Amount; /*剩余票數(shù)與乘員定額一樣*/ p2->CustName=NULL; /*該航線定票乘客頭指針為空*/ p2->ReplName=NULL; /*初始候補(bǔ)為空 */shouldsave=1; if(Continue()='n') p2->Next=NULL; /*航線的下一結(jié)點(diǎn)為空*/ return; /*-航線是否為空函數(shù)-*/int Empty_Flight() if(Head=NULL) system(&q

15、uot;cls"); printf("nt對(duì)不起,航線不存在,按任意鍵返回!"); getch(); return 1; else return 0;/*-航線查看函數(shù)-*/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請(qǐng)選擇您想要的服務(wù):"); scanf("%s",&c); switch(c) case '1':Line_Add();break;case '2':Line_search();break; case '3':Line_See();break; case '4':return; /*-訂票辦理函數(shù)-*/void bookingMenu() int Ticket_Count,ID

19、infor,i,flag=0; int Flight_No=0; /*記錄滿足條件的航線的定票結(jié)點(diǎn)*/ Flight *p1; /*記下滿足條件的航線結(jié)點(diǎn)地址*/ Customer *p2; /*臨時(shí)性定票乘員結(jié)點(diǎn)*/ Customer *p3; /*臨時(shí)性候補(bǔ)乘員結(jié)點(diǎn)*/ char answer7; /*用戶輸入的航班數(shù)據(jù)*/ char temp; char c; int tag=0; /*候補(bǔ)乘客標(biāo)志位*/ int IsRepl=0; /*是否執(zhí)行候補(bǔ)操作標(biāo)志位*/ if(Empty_Flight() /*航班線為空*/ return; while(1) printf("nt現(xiàn)在

20、您可以訂票!"); flag=0; /*標(biāo)志位清零以重新作出判斷*/ Flight_No=0; tag=0; printf("nt請(qǐng)輸入航線號(hào):"); scanf("%s",&answer); if(Find_Line(Head,answer,p1,Flight_No) /*調(diào)用航線查找函數(shù),若存在則進(jìn)行以下操作*/ while(1) /*數(shù)據(jù)合法性檢驗(yàn)*/ printf("nt請(qǐng)輸入您想要訂購(gòu)的票的數(shù)量:"); scanf("%d",&Ticket_Count); if(Ticket_C

21、ount=0) printf("nt請(qǐng)?jiān)俅屋斎腼w機(jī)號(hào):n"); getch(); else break; if(p1->Free_Amount>=Ticket_Count) Customer_Count+; /*定票乘客總數(shù)增1*/ flag=1; /*表明進(jìn)入了訂票實(shí)際操作*/ IsRepl=1; /*定票量滿足,無(wú)需進(jìn)入候補(bǔ)操作*/ if(p1->CustName=NULL) /*首個(gè)定票乘客,并記錄相關(guān)屬性*/ Custp1Flight_No=p2=new Customer; /*建立該航線的首位乘客結(jié)點(diǎn)*/ p1->CustName=Cust

22、p1Flight_No; else /*建立該航線的后續(xù)乘客結(jié)點(diǎn)*/ p2=new Customer; Custp1Flight_No->Next=p2; Custp1Flight_No=p2; IsEmpty=0; /*定票乘員不為空*/ Custp1Flight_No->Amount=Ticket_Count; /*訂票數(shù)*/ IDinfor=p1->Customer_Amount-p1->Free_Amount+1; /*算出座位號(hào)*/ Custp1Flight_No->IDinfor=IDinfor; /*賦座位號(hào)*/ p1->Free_Amount

23、-=Ticket_Count; /*減去定票數(shù)*/ printf("nt請(qǐng)輸入您的:"); scanf("%s",&Custp1Flight_No->Name); while(1) /*數(shù)據(jù)合法性檢驗(yàn)*/ printf("nt請(qǐng)輸入艙位等級(jí):"); scanf("%s",&Custp1Flight_No->Rank); if(!(Custp1Flight_No->Rank>='1'&&Custp1Flight_No->Rank<=&

24、#39;3') printf("nt輸入有誤,請(qǐng)重新輸入!"); getch(); else break; printf("nt請(qǐng)輸入您的ID信息:");scanf("%d",&Custp1Flight_No->IDinfor); if(Ticket_Count<10) /*為顯示規(guī)整,作相應(yīng)處理*/ printf("nt"); else printf("nt"); printf("nt恭喜您訂票成功!n"); for(i=1;i<=Tick

25、et_Count;i+) /*打印座位號(hào)*/ printf("nt您所預(yù)定的座位號(hào)是%d",IDinfor+); if(i%10=0) printf("nt"); printf("n"); /*滿足定票數(shù)*/ else if(p1->Free_Amount=0) printf("nt對(duì)不起,票已售完!n"); IsRepl=0; else printf("nt對(duì)不起,當(dāng)前沒(méi)有多余的票!n"); IsRepl=0; if(!IsRepl) printf("nt您是否想成為候補(bǔ)乘客(

26、Y/N)?"); scanf("%s",&temp); if(temp='y'|temp='Y')/*以下為候補(bǔ)操作*/ if(p1->ReplName=NULL) Replp1Flight_No=p3=new Customer; /*建立該航線的首位候補(bǔ)乘客結(jié)點(diǎn)*/ p1->ReplName=Replp1Flight_No; else p3=new Customer; Replp1Flight_No->Next=p3; Replp1Flight_No=p3; IsReplace=0; /*候補(bǔ)乘客不為空*

27、/ tag=1; /*已選擇列入候補(bǔ)乘客*/ Replp1Flight_No->Amount=Ticket_Count; printf("nt請(qǐng)輸入您的:"); scanf("%s",&Replp1Flight_No->Name); Replp1Flight_No->IDinfor=IDinfor; /*候補(bǔ)乘客的座位*/ Replp1Flight_No->Amount=Ticket_Count; /*候補(bǔ)乘客的訂票數(shù)*/ while(1) /*數(shù)據(jù)合法性檢驗(yàn)*/ printf("nt請(qǐng)輸入艙位等級(jí):"

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

29、rintf("nt沒(méi)有剩余座位!n");/*候補(bǔ)乘客無(wú)座提示*/shouldsave=1; /*進(jìn)入候補(bǔ) */ /*票數(shù)滿足*/ /*航線存在*/ else printf("nt對(duì)不起,航線不存在!n");/*航線不存在*/ if(flag) /*此處不作處理,則會(huì)地址溢出*/ Custp1Flight_No->Next=NULL;/*末位定票乘客的指針置空*/ if(tag) Replp1Flight_No->Next=NULL;/*末位候補(bǔ)乘客的指針置空*/ printf("nt您已經(jīng)成功排入候補(bǔ)訂票隊(duì)列中!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對(duì)不起,沒(méi)有訂票乘客信息!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;/*-候補(bǔ)乘客信息-*/void Display_Replace() system

33、("cls"); Flight *p1; Customer *p2; p1=Head; if(Empty_Flight() return; printf("nt候補(bǔ)乘客信息!"); if(IsReplace) printf("nt對(duì)不起,沒(méi)有候補(bǔ)乘客!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;/*-退票辦理函數(shù)-*/void RefundticketMenu() int Flight_No=0,flag=0; /*記錄滿足條件的航線的定票結(jié)點(diǎn)*/ Flight *p1; /*記下滿足條件的航線結(jié)點(diǎn)地址*/ Customer *p2,*p4; /*臨時(shí)性定票乘員結(jié)點(diǎn)*/ Customer *p3,*p5; /*臨時(shí)性候補(bǔ)乘員結(jié)點(diǎn)*/ char answer7

36、,name7; /*用戶輸入的航班數(shù)據(jù)*/ int tag=0; /*若第二乘客滿足條件,則它的首地址會(huì)發(fā)生沖突,注意此處*/ int IDinfor; /*記錄座位號(hào)*/ if(Empty_Flight() /*航班線為空*/ return; printf("nt現(xiàn)在開(kāi)始進(jìn)行退票手續(xù)"); if(IsEmpty) printf("nt對(duì)不起,乘客不存在!"); getch(); return; while(1) flag=0; tag=0; Flight_No=0; printf("nt請(qǐng)輸入航線:"); scanf("%

37、s",&answer); if(Find_Line(Head,answer,p1,Flight_No) /*航線存在*/ p2=p1->CustName; /*指向該航線的乘客的首地址 */ printf("nt請(qǐng)輸入您的:"); scanf("%s",&name); if(p2=NULL) /*該航線無(wú)定票乘客*/ printf("nt對(duì)不起,乘客不存在!."); if(Continue()='n')/*是否繼續(xù)操作*/ return; else while(p2!=NULL)/*查找

38、有無(wú)此乘客名*/ if(strcmp(p2->Name,name)=0)/*此外括號(hào)不能省略,否則功能會(huì)轉(zhuǎn)變*/ if(p2=p1->CustName) /*若為首位乘客滿足*/ prior=p1->CustName; /*記錄指針*/ IDinfor=p2->IDinfor; flag=1; break; else if(p2->Next!=NULL)/*記錄滿足航線的的前結(jié)點(diǎn)地址 */ if(strcmp(p2->Next->Name,name)=0) tag=1; /*特別注意此處*/ prior=p2; /*記錄滿足定乘客的前一地址,以作刪除操

39、作*/ IDinfor=p2->Next->IDinfor; flag=1; break; p2=p2->Next; /*指向下一乘客結(jié)點(diǎn)*/shouldsave=1; /*while */ if(!flag) printf("nt對(duì)不起,乘客不存在!n"); /*存在該航線*/ else printf("nt對(duì)不起,航線不存在!n"); if(flag) if(prior=p1->CustName&&!tag) /*首結(jié)點(diǎn)滿足條件且一個(gè)乘客,則該航線定票乘客置空*/ if(prior->Next=NULL)

40、 /*僅一乘客,頭指針置空*/ p1->Free_Amount+=prior->Amount; p1->CustName=NULL; else p1->Free_Amount+=prior->Next->Amount; p1->CustName=prior->Next; /*指向下一乘客結(jié)點(diǎn)*/ 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)/*候補(bǔ)乘客的定票數(shù)小于或等于剩余票數(shù)*/ printf("nt候補(bǔ)乘客已經(jīng)存在!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; /*減去相應(yīng)的票數(shù)*/ Customer_Count+; if(p3->Next=NULL) /*無(wú)候補(bǔ)乘客 */ 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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論