數據結構課程設計(航空客運訂票系統(tǒng))_第1頁
數據結構課程設計(航空客運訂票系統(tǒng))_第2頁
數據結構課程設計(航空客運訂票系統(tǒng))_第3頁
數據結構課程設計(航空客運訂票系統(tǒng))_第4頁
數據結構課程設計(航空客運訂票系統(tǒng))_第5頁
已閱讀5頁,還剩13頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

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;/*-詢問是否繼續(xù)的函數-*/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輸入有誤,請重新輸入!"); /*-操作出錯函數-*/void ErrorMess() printf("nt對不起,您的操作有誤!");getch();/*-系統(tǒng)退出函數-*/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;/*-航線查找函數-*/*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) /*遇結束符不作統(tǒng)計圍*/ 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; /*是否執(zhí)行候補操作標志位*/ 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 /*建立該航線的后續(xù)乘客結點*/ 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) /*為顯示規(guī)整,作相應處理*/ 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; /*若第二乘客滿足條件,則它的首地址會發(fā)生沖突,注意此處*/ int IDinfor; /*記錄座位號*/ if(Empty_Flight() /*航班線為空*/ return; printf("nt現在開始進行退票手續(xù)"); 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')/*是否繼續(xù)操作*/ 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. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論