




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、 (大學(xué)計算機(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; /*艙位等級*/ int IDinfor; /
2、*個人信息*/ struct Customer *Next; /*指向下一乘客結(jié)點*/Customer;typedef struct Flight /*航線信息*/ char Des_Name10; /*終點站名*/ char Flight_No6; /*航班號*/ char Plane_No6; /*飛機(jī)號*/ int Week_Day; /*飛行周日*/ int Customer_Amount; /*乘員定額*/ int Free_Amount; /*剩余票數(shù)*/ int Price3; /*艙位等級的價格*/ Customer *CustName; /*該航班的已定票乘客*/ Custo
3、mer *ReplName; /*該航班的候補乘客*/ struct Flight *Next; /*指示下一航線結(jié)點*/Flight,*PFlight;int Customer_Count=0; /*所有航線的定票乘客總數(shù)*/Flight *Head; /*航線頭指針*/Flight *p2; /*航線結(jié)點指針*/Customer *Custp1MAX; /*各條航線乘客結(jié)點指針*/Customer *Replp1MAX; /*各條航線候補結(jié)點指針*/int IsEmpty=1; /*是否有定票乘客*/int IsReplace=1; /*是否有候補乘客*/Customer *prior;
4、/*滿足要求的定票乘客的前結(jié)點,以作刪除操作*/int shouldsave=0;/*-詢問是否繼續(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輸入有誤,請重新輸入!"); /*-操作出錯函數(shù)-*/void ErrorMess() printf("nt對不起,您的操作有誤!");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)/*核對航線是否唯一*/ int flag=0; /*該標(biāo)志位0表示未找到相關(guān)信息,反之即找到,以下標(biāo)志位同理*/ 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;/*指向下一航班結(jié)點*/ 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é)點*/ while(p1!=NULL) if(strcmp(p1->Flight_No,key)=0)/*不包括當(dāng)前航線*/ flag=1; p2=p1; break; p1=p1->Next; /*指向下
8、一航班結(jié)點*/ if(p1!=NULL) /*遇結(jié)束符不作統(tǒng)計圍*/ Flight_No+; return flag;/*-航班查找函數(shù)-*/void Line_search() Flight *p1; p1=Head; char Desname50;/查詢終點站航班關(guān)鍵字 if(Head=NULL) printf("nt沒有到達(dá)您想要的終點站的航班!");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(); /*-航線添加函數(shù)-*/void Line_Add() Flight *p1; /*建立臨時航線結(jié)點*/ while(1) if(Head=NULL)/*航線為空*/ p1=p2=new Flight; /*建立首個航線*/ Head=p2; else p1=new Flight; /*建立航線結(jié)點*
11、/ p2->Next=p1; /*前一航線結(jié)點指向當(dāng)前航班結(jié)點*/ p2=p1; /*保留當(dāng)前航班結(jié)點地址*/ printf("nt添加新的航線!n"); printf("nt請輸入終點站名:"); scanf("%s",&p2->Des_Name); while(1) /*數(shù)據(jù)合法性檢驗*/ printf("nt請輸入唯一的航班號:"); scanf("%s",&p2->Flight_No); if(Find_Line(Head,p2->Flight_N
12、o) /*存在航班號*/ printf("nt航班號已經(jīng)存在!n"); else break; printf("nt請輸入飛機(jī)號:"); 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請輸入座位數(shù)量:"); 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; /*剩余票數(shù)與乘員定額一樣*/ p2->CustName=NULL; /*該航線定票乘客頭指針為空*/ p2->ReplName=NULL; /*初始候補為空 */shouldsave=1; if(Continue()='n') p2->Next=NULL; /*航線的下一結(jié)點為空*/ return; /*-航線是否為空函數(shù)-*/int Empty_Flight() if(Head=NULL) system(&q
15、uot;cls"); printf("nt對不起,航線不存在,按任意鍵返回!"); 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請選擇您想要的服務(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é)點*/ Flight *p1; /*記下滿足條件的航線結(jié)點地址*/ Customer *p2; /*臨時性定票乘員結(jié)點*/ Customer *p3; /*臨時性候補乘員結(jié)點*/ char answer7; /*用戶輸入的航班數(shù)據(jù)*/ char temp; char c; int tag=0; /*候補乘客標(biāo)志位*/ int IsRepl=0; /*是否執(zhí)行候補操作標(biāo)志位*/ if(Empty_Flight() /*航班線為空*/ return; while(1) printf("nt現(xiàn)在
20、您可以訂票!"); flag=0; /*標(biāo)志位清零以重新作出判斷*/ Flight_No=0; tag=0; printf("nt請輸入航線號:"); scanf("%s",&answer); if(Find_Line(Head,answer,p1,Flight_No) /*調(diào)用航線查找函數(shù),若存在則進(jìn)行以下操作*/ while(1) /*數(shù)據(jù)合法性檢驗*/ printf("nt請輸入您想要訂購的票的數(shù)量:"); scanf("%d",&Ticket_Count); if(Ticket_C
21、ount=0) printf("nt請再次輸入飛機(jī)號:n"); getch(); else break; if(p1->Free_Amount>=Ticket_Count) Customer_Count+; /*定票乘客總數(shù)增1*/ flag=1; /*表明進(jìn)入了訂票實際操作*/ IsRepl=1; /*定票量滿足,無需進(jìn)入候補操作*/ if(p1->CustName=NULL) /*首個定票乘客,并記錄相關(guān)屬性*/ Custp1Flight_No=p2=new Customer; /*建立該航線的首位乘客結(jié)點*/ p1->CustName=Cust
22、p1Flight_No; else /*建立該航線的后續(xù)乘客結(jié)點*/ 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; /*算出座位號*/ Custp1Flight_No->IDinfor=IDinfor; /*賦座位號*/ p1->Free_Amount
23、-=Ticket_Count; /*減去定票數(shù)*/ printf("nt請輸入您的:"); scanf("%s",&Custp1Flight_No->Name); while(1) /*數(shù)據(jù)合法性檢驗*/ 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ī)整,作相應(yīng)處理*/ printf("nt"); else printf("nt"); printf("nt恭喜您訂票成功!n"); for(i=1;i<=Tick
25、et_Count;i+) /*打印座位號*/ printf("nt您所預(yù)定的座位號是%d",IDinfor+); if(i%10=0) printf("nt"); printf("n"); /*滿足定票數(shù)*/ else if(p1->Free_Amount=0) printf("nt對不起,票已售完!n"); IsRepl=0; else printf("nt對不起,當(dāng)前沒有多余的票!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; /*建立該航線的首位候補乘客結(jié)點*/ 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; /*候補乘客的訂票數(shù)*/ while(1) /*數(shù)據(jù)合法性檢驗*/ 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; /*進(jìn)入候補 */ /*票數(shù)滿足*/ /*航線存在*/ else printf("nt對不起,航線不存在!n");/*航線不存在*/ if(flag) /*此處不作處理,則會地址溢出*/ Custp1Flight_No->Next=NULL;/*末位定票乘客的指針置空*/ if(tag) Replp1Flight_No->Next=NULL;/*末位候補乘客的指針置空*/ printf("nt您已經(jīng)成功排入候補訂票隊列中!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;/*-退票辦理函數(shù)-*/void RefundticketMenu() int Flight_No=0,flag=0; /*記錄滿足條件的航線的定票結(jié)點*/ Flight *p1; /*記下滿足條件的航線結(jié)點地址*/ Customer *p2,*p4; /*臨時性定票乘員結(jié)點*/ Customer *p3,*p5; /*臨時性候補乘員結(jié)點*/ char answer7
36、,name7; /*用戶輸入的航班數(shù)據(jù)*/ int tag=0; /*若第二乘客滿足條件,則它的首地址會發(fā)生沖突,注意此處*/ int IDinfor; /*記錄座位號*/ if(Empty_Flight() /*航班線為空*/ return; printf("nt現(xiàn)在開始進(jìn)行退票手續(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)/*此外括號不能省略,否則功能會轉(zhuǎn)變*/ if(p2=p1->CustName) /*若為首位乘客滿足*/ prior=p1->CustName; /*記錄指針*/ IDinfor=p2->IDinfor; flag=1; break; else if(p2->Next!=NULL)/*記錄滿足航線的的前結(jié)點地址 */ if(strcmp(p2->Next->Name,name)=0) tag=1; /*特別注意此處*/ prior=p2; /*記錄滿足定乘客的前一地址,以作刪除操
39、作*/ IDinfor=p2->Next->IDinfor; flag=1; break; p2=p2->Next; /*指向下一乘客結(jié)點*/shouldsave=1; /*while */ if(!flag) printf("nt對不起,乘客不存在!n"); /*存在該航線*/ else printf("nt對不起,航線不存在!n"); if(flag) if(prior=p1->CustName&&!tag) /*首結(jié)點滿足條件且一個乘客,則該航線定票乘客置空*/ 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é)點*/ 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)/*候補乘客的定票數(shù)小于或等于剩余票數(shù)*/ printf("nt候補乘客已經(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) /*無候補乘客 */ 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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 計量力學(xué)試題及答案
- 太原人力資源師考試試題及答案
- 勞務(wù)企業(yè)勞務(wù)費結(jié)算、支付和工資支付情況報
- 臥床癱瘓病人康復(fù)護(hù)理
- 2025年中國攀爬網(wǎng)行業(yè)市場全景分析及前景機(jī)遇研判報告
- 2025年中國女性衛(wèi)生品行業(yè)市場全景分析及前景機(jī)遇研判報告
- 2025年中國捏褶窗簾行業(yè)市場全景分析及前景機(jī)遇研判報告
- 護(hù)理學(xué)基礎(chǔ)心肺復(fù)蘇說課
- 煤炭塌陷區(qū)景觀優(yōu)化設(shè)計
- 腫瘤化學(xué)治療患者護(hù)理
- 東營市廣饒縣2025屆五年級數(shù)學(xué)第二學(xué)期期末學(xué)業(yè)水平測試模擬試題含答案
- 自行車智能化發(fā)展趨勢-深度研究
- 2022火電廠鐵路專用線安全管理標(biāo)準(zhǔn)
- 《2025年煤礦開工第一課培訓(xùn)》專題講座
- 食品檢驗員持證上崗培訓(xùn)課件
- 2025年中國速凍水餃行業(yè)供需態(tài)勢、競爭格局及投資前景分析報告(智研咨詢)
- 臨床教學(xué)師資培訓(xùn)
- 弱電工程項目經(jīng)理職責(zé)
- 青馬工程培訓(xùn)班培訓(xùn)課件
- 雙碳知識培訓(xùn)
- 新交際英語(2024新版)一年級上冊Unit 1~6全冊教案
評論
0/150
提交評論