国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

C++實現(xiàn)機票預(yù)訂系統(tǒng)

2020-01-26 13:33:14
字體:
供稿:網(wǎng)友

C++編寫一個簡單的機票預(yù)訂系統(tǒng)。該程序顯示一個帶有下列選項的菜單:預(yù)訂機票、取消預(yù)訂、查看某人是否預(yù)定了機票,以及顯示預(yù)訂乘客。這些信息保存在一個按照字母排列的名字鏈表中。在程序的簡化版中,假設(shè)只為一趟航班預(yù)訂機票。在完全版中不再限制航班的數(shù)目。創(chuàng)建一個航班鏈表,其中每個節(jié)點都指向乘客鏈表的指針。

/*******************list.h**********************/#include <iostream>#include <malloc.h>#include <string.h> using namespace std;typedef struct TK{ char Name[20]; int SeatId; struct TK *next;}Ticket;  typedef struct FLY{ char FlightId[10]; int Seat[50]; Ticket *PersonHead; struct FLY *next;}Flight;  class Person{public: void ListInitiate(Flight **head); bool Check(int *Seat,int Ch); void Insert(Flight *head); int Delete(Flight *head); void show(Flight *head); void Search(Flight *head); void AddFlght(Flight *head); void DeleteFlght(Flight *head);}; /*******************************main.cpp**********************/#include "list.h" int menu(){ int option; cout<<endl<<endl; cout<<"主菜單"<<endl; cout<<" 1.Booking the ticket of flighting"<<endl; cout<<" 2.Cancel the flighting"<<endl; cout<<" 3.Display the information "<<endl; cout<<" 4.Search"<<endl; cout<<" 5.Add a Flight"<<endl; cout<<" 6.Delete a Flight"<<endl; cout<<" 0.Exit"<<endl<<endl; cout<<"Please input your option:"; cin>>option; getchar(); cout<<endl; if(option>=0&&option<=6) return option; else  return -1;}int main(){   cout<<"------------------------->航班管理系統(tǒng)<<<<-----------------------------"<<endl; cout<<"  歡迎你使用該航班系統(tǒng)"<<endl; Flight *head; Person P; P.ListInitiate(&head); while(true) { switch(menu( )) { case 1:P.Insert(head);break; //預(yù)訂 case 2:P.Delete(head);break; //取消 case 3:P.show(head);break; //顯示 case 4:P.Search(head);break; //查詢 case 5:P.AddFlght(head);break; //添加航班 case 6:P.DeleteFlght(head);break; //刪除航班 case 0:exit(0); default:cout<<"Choice error!/n"; } }  return 0;}/*****************************************passenger.cpp*************************/#include "List.h"void Person::ListInitiate(Flight **head){ int count=0; *head = (Flight *)malloc(sizeof(Flight)); (*head)->PersonHead=(Ticket *)malloc(sizeof(Ticket)); (*head)->PersonHead->next=NULL; (*head)->next=NULL; for(int i=0;i<50;i++) { (*head)->Seat[i]=0; }} bool Person::Check(int *Seat,int Ch){ int i; for(int i=0;i<50;i++) { if(Ch==i&&Seat[i]!=1)return 1; } return 0;}Flight* Index(Flight *head,char *Id){ Flight *p=head->next;  while(p) { if(strcmp(p->FlightId,Id)==0) { return p; } p=p->next; }  return NULL;}/*******************************預(yù)定******************************/void Person::Insert(Flight *head){ int count=0; int Ch; Flight *s=head;  if(s->next==NULL) { cout<<"暫無航班!"<<endl; return ; } cout<<"航班列表:"<<endl; s=s->next; while(s!=NULL) { puts(s->FlightId); count++; if(count%5==0) cout<<"/n"; s=s->next; } count=0; char FID[10]; cout<<"輸入航班ID:"; gets(FID); s=Index(head,FID); if(s==NULL) { cout<<"輸入ID有誤"<<endl; return; } cout<<endl; cout<<"有以下座位可供選擇:"<<endl; for(int i=0;i<50;i++) { if(s->Seat[i]!=1) { cout<<i<<"號"<<"/t"; count++; if(count%5==0) cout<<"/n"; } } cout<<endl; cout<<"輸入座位號:/n"; cin>>Ch; getchar(); if(!Check(head->Seat,Ch)) { cout<<"This Seat have been booked or it is non-existent"; return ; } s->Seat[Ch]=1; char name[20]; cout<<endl; cout<<"Input your Name:"; gets(name); Ticket *p=s->PersonHead,*q;  while(p->next!=NULL) {  if(strcmp(p->next->Name,name)>0) break; p=p->next; }  q=(Ticket *)malloc(sizeof(Ticket)); q->next=p->next; p->next=q; strcpy(q->Name,name); q->SeatId=Ch;} /*******************************取消預(yù)定******************************/int Person::Delete(Flight *head){ char name[20],FID[10]; cout<<"Input your Name:"; gets(name); getchar(); Flight *s; cout<<"Input the Flight ID:"; gets(FID); s=Index(head,FID); if(s==NULL) { cout<<"輸入ID有誤"<<endl; return 0; }  Ticket *p=s->PersonHead->next,*pre=s->PersonHead; int flag=0; while(p!=NULL) { if(strcmp(p->Name,name)==0){ flag=1; break;  } pre=p; p=p->next; } if(flag==1){ pre->next=p->next; s->Seat[p->SeatId]=0; free(p); cout<<"你的機票已經(jīng)取消成功"; } else  { cout<<"您還沒訂票/n"; return 0;  } return 1;}/*******************************顯示信息******************************/void Person::show(Flight *head){ Flight *s; char FID[10]; cout<<"Input The Flight ID:"; gets(FID); s=Index(head,FID); if(s==NULL) { cout<<"輸入ID有誤"<<endl; return; } Ticket *p=s->PersonHead->next; if(p==NULL) { cout<<"還沒乘客訂票"<<endl; return; } while(p!=NULL) { cout<<"乘客: "<<p->Name<<" 座位號:" <<p->SeatId; p=p->next; }} /*******************************查詢相關(guān)信息******************************/void Person::Search(Flight *head){ char name[20]; cout<<"Input Your Name:"; gets(name); Flight *s; char FID[10]; cout<<"Input The Flight ID:"; gets(FID); s=Index(head,FID); if(s==NULL) { cout<<"輸入ID有誤"<<endl; return; } Ticket *p=s->PersonHead->next; int flag=0; while(p!=NULL) { if(strcmp(p->Name,name)==0){ flag=1; break;  } p=p->next; } if(flag==1){ cout<<name<<" 已訂機票"<<endl; } else  { cout<<name<<" 未訂機票"<<endl; }}/*******************************增加航班**********************************/void Person::AddFlght(Flight *head){ char FlightID[10]; Flight *p=head,*q; cout<<" 輸入航班ID:"; gets(FlightID); while(p->next) { p=p->next; }  ListInitiate(&q); p->next=q; strcpy(q->FlightId,FlightID); cout<<"――航班已添加成功!";}/**********************************刪除航班*******************************************/void Person::DeleteFlght(Flight *head){ char FlightID[10]; int flag=0; Flight *p=head->next,*q=head;  int count=0; Flight *s=head;  if(s->next==NULL) { cout<<" 暫無航班!"<<endl; return ; } cout<<" 航班列表:"<<endl; s=s->next; while(s!=NULL) { cout<<s->FlightId<<endl; count++; if(count%5==0) cout<<"/n"; s=s->next; } cout<<" 輸入航班ID:"; gets(FlightID); while(p) { if(strcmp(p->FlightId,FlightID)==0) { flag=1;break; } q=p; p=p->next; } if(flag==0) { cout<<" 該航班ID不存在!"; return ; } q->next=q->next->next; free(p); cout<<" 航班已刪除!/n";}

效果如下:

更多學(xué)習(xí)資料請關(guān)注專題《管理系統(tǒng)開發(fā)》。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 韩城市| 静乐县| 阿巴嘎旗| 阳信县| 嘉义市| 十堰市| 哈巴河县| 湖南省| 杭锦旗| 揭阳市| 东兴市| 宜都市| 新丰县| 留坝县| 瓮安县| 涿鹿县| 开鲁县| 丁青县| 德昌县| 莱阳市| 香港 | 商水县| 平邑县| 闵行区| 固原市| 新郑市| 海宁市| 松阳县| 垫江县| 融水| 上高县| 大埔县| 旅游| 都兰县| 临泉县| 新蔡县| 合江县| 集安市| 太和县| 开化县| 枝江市|