航空订票系统

更新时间:2024-07-01 18:00:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

//包含头文件 #include #include #include #include #define MAX 60

//乘客信息结构体定义 typedef struct Customer {

char Name[8]; int IDinfor; int Amount; char Flight_No[6]; int Number; struct Customer *Next; }Customer;

//航班信息结构体定义 typedef struct Flight {

char Flight_No[6]; char Sta_Name[10]; char Des_Name[10]; char Sta_Time[10]; char Des_Time[10]; int Price; int Customer_Amount; int Free_Amount; int Discount; Customer *CustName; Customer *ReplName; struct Flight *Next; }Flight,*PFlight; //全局变量定义

int Customer_Count=0; Flight *Head=NULL; Flight *p2; Customer *Custp1[MAX]; Customer *Replp1[MAX]; int IsEmpty=1; int IsReplace=1; Customer *prior; int shouldsave=0;

//姓名 //证件号 //订票数 //航班号 //订单编号 //指向下一乘客结点 //航班号 //出发城市 //到达城市 //起飞时间 //到达时间 //价格 //总票数 //剩余票数 //折扣率 //已订票乘客名单 //候补乘客名单 //指示下一航班结点 //所有航班的订票总数 //航班头指针 //航班结点指针

//各航班乘客节点指针 //各航班候补节点指针 //是否有订票乘客 //是否有候补乘客

//满足要求的所有订票乘客的前节点,用于删除操作

//1.询问是否继续的函数 char Continue() { char answer; while(1) { printf(\您是否想继续(Y/N)?\ scanf(\ system(\ if(answer=='y'||answer=='Y') return 'y'; else if(answer=='n'||answer=='N') return 'n';

else printf(\输入有误,请重新输入!\ } }

//2.操作出错函数 void ErrorMess() {

printf(\对不起,您的输入有误!\ getch(); }

//3-1.核对航班函数

int Find_Line1(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; break; } p1=p1->Next; } return flag;

}

//3-2.按航班号查询函数

int Find_Line2(PFlight L,char *key,PFlight *pp,int *Flight_No) { int flag=0; Flight *p1; p1=L; while(p1!=NULL) { if(strcmp(p1->Flight_No,key)==0) { flag=1; *pp=p1; break; } p1=p1->Next; if(p1!=NULL) Flight_No++; } return flag; }

//4.按目录地查询航班函数 void Line_search() { char Desname[50]; //终点站航班关键字 Flight *p1=Head; if(Head==NULL) {

printf(\没有达到您想要的终点站的航班!\ getch(); return; } printf(\请输入终点站名:\ scanf(\ printf(\您所查询的航班信息:\\n\ printf(\___________\\n\ while(p1!=NULL) { if(strcmp(p1->Des_Name,Desname)==0)

{

printf(\航班号 出发城市 到达城市 起飞时间 到达时间 价格 折扣率(%) 总票数 剩余票数\\n\ printf(\Des_Name, p1->Sta_Time,p1->Des_Time,p1->Price,p1->Discount,p1->Customer_Amount,p1->Free_Amount); } p1=p1->Next; } printf(\____________\\n\ Continue(); }

//5.航班添加函数 void Line_Add() { PFlight *p1; p1=&Head; while(1) { if(Head==NULL) { *p1=(PFlight)malloc(sizeof(Flight)); (*p1)->Next=NULL; p2=Head; } else { *p1=(PFlight)malloc(sizeof(Flight)); p2->Next=*p1; p2=*p1; } printf(\添加新的航班!\\n\ while(1) { printf(\请输入唯一的航班号:\ scanf(\ if(Find_Line1(Head,p2->Flight_No)) printf(\航班号已存在!\\n\

else break; }

printf(\请输入起始站名:\scanf(\

printf(\请输入终点站名:\scanf(\

printf(\请输入航班起飞时间:\scanf(\

printf(\请输入航班到达时间:\scanf(\printf(\请输入飞机票价:\scanf(\printf(\请输入折扣率:\scanf(\

printf(\请输入座位数量:\ scanf(\ p2->Free_Amount=p2->Customer_Amount; p2->CustName=NULL; p2->ReplName=NULL; shouldsave=1; if(Continue()=='n') { p2->Next=NULL; return; } } }

//6.判航班是否为空函数 int Empty_Flight() { if(Head==NULL) { system(\

printf(\对不起,航班不存在,按任意键返回!\ getch(); return 1; } else return 0; }

//7.航班查看函数

void Line_See() { Flight *p1; system(\ p1=Head; if(Empty_Flight()) return; printf(\航班信息:\\n\ printf(\n\

printf(\航班号 出发城市 到达城市 起飞时间 到达时间 价格 折扣率(%) 总票数 剩余票数\\n\ while(p1!=NULL) { printf(\Des_Name, p1->Sta_Time,p1->Des_Time,p1->Price,p1->Discount,p1->Customer_Amount,p1->Free_Amount); p1=p1->Next; } printf(\\\n\ }

printf(\按任意键返回!\\n\getch();

//8.航班管理菜单

void LinemanageMenu() { char c; system(\ while(1) { printf(\航班管理菜单:\ printf(\ printf(\ 1.添加新的航班\\n\ printf(\ 2.查询航班 \\n\ printf(\ 3.查看航班 \\n\ printf(\ 4.返回主菜单 \\n\ printf(\

}

}

printf(\请选择您想要的服务:\scanf(\switch(c) {

case'1':Line_Add();break; case'2':Line_search();break; case'3':Line_See();break; case'4':return; }

//9.订票办理系统 void bookingMenu() { int Ticket_Count,IDinfor,i,flag=0; int flight_no=0; Flight *p1; Customer *c1; Customer *c2; char answer[7]; char temp,c; int tag=0; int IsRepl=0; if(Empty_Flight()) return; while(1) { printf(\现在您可以订票!\ flag=0; flight_no=0; tag=0; printf(\请输入航班号:\ scanf(\ if(Find_Line2(Head,answer,&p1,&flight_no)) { while(1) { printf(\请输入您想要订购的票的数量:\ scanf(\ if(Ticket_Count==0) { printf(\请再次输入订票数量:\\n\

getch(); } else break; }

if(p1->Free_Amount>=Ticket_Count) { Customer_Count++; flag=1; IsRepl=1; if(p1->CustName==NULL) { Custp1[flight_no]=c1=(Customer*)malloc(sizeof(Customer)); p1->CustName=Custp1[flight_no]; } else { c1=(Customer*)malloc(sizeof(Customer)); Custp1[flight_no]->Next=c1; Custp1[flight_no]=c1; } IsEmpty=0; Custp1[flight_no]->Amount=Ticket_Count; IDinfor=p1->Customer_Amount-p1->Free_Amount+1; Custp1[flight_no]->IDinfor=IDinfor; p1->Free_Amount-=Ticket_Count;

printf(\请输入您的姓名:\scanf(\

printf(\请输入您的ID信息:\ scanf(\ strcpy(Custp1[flight_no]->Flight_No, answer); if(Ticket_Count<10) printf(\ else printf(\ printf(\恭喜您订票成功!\\n\ for(i=1;i<=Ticket_Count;i++) { printf(\您预订的座位号是%d\ if(i==0) printf(\ } printf(\}

else if(p1->Free_Amount==0)

{

printf(\对不起,票已售完!\\n\ IsRepl=0; } else { printf(\对不起,当前没有多余的票!\\n\ IsRepl=0; }

if(!IsRepl) { printf(\您是否想成为候补乘客(Y/N)?\ scanf(\ if(temp=='y'||temp=='Y') { if(p1->ReplName==NULL) { c2=(Customer*)malloc(sizeof(Customer)); Replp1[flight_no]=c2; p1->ReplName=Replp1[flight_no]; } else { c2=(Customer*)malloc(sizeof(Customer)); Replp1[flight_no]->Next=c2; Replp1[flight_no]=c2; } IsReplace=0; tag=1; Replp1[flight_no]->Amount=Ticket_Count; printf(\请输入您的姓名:\ scanf(\ Replp1[flight_no]->IDinfor=IDinfor; Replp1[flight_no]->Amount=Ticket_Count; printf(\请输入您的ID信息:\ scanf(\ printf(\没有剩余座位!\\n\ shouldsave=1; } } } else printf(\对不起,航班不存在!\\n\if(flag)

}

}

Custp1[flight_no]->Next=NULL; if(tag) { Replp1[flight_no]->Next=NULL;

printf(\您已将成功排入候补订票队列中!\\n\}

printf(\是否退出菜单?:(Y/N)\scanf(\if(c=='y'||c=='Y') return;

//10.订票乘客信息

void Display_Reserve() { Flight *p1; Customer *c1; system(\ p1=Head; if(Empty_Flight()) return; printf(\订票乘客信息\\n\ if(IsEmpty) { printf(\对不起,没有订票乘客信息!\\n\ getch(); return; } printf(\ printf(\姓名 证件号 订票数 航班号\\n\ while(p1!=NULL) { if(p1->CustName!=NULL) { c1=p1->CustName; while(c1!=NULL) { printf(\

}

if(p1->Free_Amount>=1)

printf(\还有多余的票!\\n\ else printf(\票已售完!\\n\ c1=c1->Next; } } p1=p1->Next;

printf(\ }

printf(\按任意键返回!\getch(); return;

//11.候补乘客信息 void Display_Replace() { Flight *p1; Customer *c1; system(\ p1=Head; if (Empty_Flight()) return;

printf(\候补乘客信息!\if(IsReplace) { printf(\对不起,没有候补乘客!\ getch(); return; }

printf(\printf(\姓名 证件号 订票数 航班号\\n\while(p1!=NULL) { if(p1->ReplName!=NULL) { c1=p1->ReplName; while(c1!=NULL) {

printf(\ if(p1->Free_Amount>=1)

}

printf(\还有多余的票!\\n\ else printf(\票已售完!\\n\ c1=c1->Next; } } p1=p1->Next; }

printf(\printf(\按任意键返回!\getch(); return;

//12.退票办理函数

void RefundticketMenu() { int Flight_No=0,flag=0; Flight *p1; Customer *c2,*c4; Customer *c3,*c5; char answer[7],name[7]; int tag=0; int IDinfor; if(Empty_Flight()) return; printf(\现在开始进行退票手续\ if(IsEmpty) { printf(\对不起,乘客不存在!\ getch(); return; } while(1) { flag=0;tag=0;Flight_No=0; printf(\请输入航班:\ scanf(\ if(Find_Line2(Head,answer,&p1,&Flight_No)) { c2=p1->CustName; printf(\请输入您的姓名:\ scanf(\ if(c2==NULL)

}

{

printf(\对不起,客户不存在!\ if(Continue()=='n') return; } else while(c2!=NULL) { if(strcmp(c2->Name,name)==0) { if(c2==p1->CustName) { prior=p1->CustName; IDinfor=c2->IDinfor; flag=1; break; } } else if(c2->Next!=NULL) { if(strcmp(c2->Next->Name,name)==0) { tag=1; prior=c2; IDinfor=c2->Next->IDinfor; flag=1; break; } } c2=c2->Next; shouldsave=1; } if(!flag) printf(\对不起,乘客不存在!\\n\

else printf(\对不起,航班不存在!\\n\if(flag) { if(prior==p1->CustName && !tag) { if(prior->Next==NULL) { 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(Customer_Count==0) IsEmpty=1; shouldsave=1; }

if(flag) { c3=p1->ReplName; while(c3!=NULL) { if(c3->Amount<=p1->Free_Amount) {

printf(\候补乘客已存在!\\n\

c4=(Customer*)malloc(sizeof(Customer)); Custp1[Flight_No]->Next=c4; c4->Next=NULL; IsEmpty=0;

if(p1->CustName==NULL) strcpy(c4->Name,c3->Name); c4->Amount=c3->Amount; c4->IDinfor=IDinfor;

p1->Free_Amount-=c3->Amount; Customer_Count++; if(c3->Next==NULL) IsReplace=1; if(p1->ReplName==c3) { if(p1->ReplName->Next==NULL) p1->ReplName=NULL; else p1->ReplName=c3->Next; }

}

}

}

else c5->Next=c3->Next->Next; break; }

if(c3->Next!=NULL) if(c3->Next->Amount<=p1->Free_Amount) c5=c3; c3=c3->Next; shouldsave=1;

printf(\退票成功!\

getch(); return; }

shouldsave=1; if(Continue()=='n') return;

//13.乘客管理子菜单函数

void CustomermagMenu() { char c; system(\ while(1) { }

}

printf(\乘客菜单:\\n\

printf(\printf(\ 1.乘客信息 \\n\printf(\ 2.候补乘客信息 \\n\printf(\ 3.返回主菜单 \\n\

printf(\printf(\请选择您需要的服务:\scanf(\switch(c) {

case '1':Display_Reserve();break; case '2':Display_Reserve();break; case '3':Display_Reserve();break; default:ErrorMess(); }

//主函数 int main() { char c; system(\ system(\ do{ system(\ }

printf(\ 航空客运订票系统主菜单\\n\

printf(\

printf(\ 1.航班管理菜单\\n\ printf(\ 2.订票办理菜单\\n\ printf(\ 3.退票办理菜单\\n\ printf(\ 4.乘客管理菜单\\n\ printf(\ 5.退出系统\\n\ printf(\谢谢使用航空客运订票系统********************\\n\ printf(\请选择您想要的服务:\ scanf(\ switch(c) { case'1':LinemanageMenu();break; case'2':bookingMenu();break; case'3':RefundticketMenu();break; case'4':CustomermagMenu();break; case'5':exit(0); default:break; }

}while(c!='5');

//主函数 int main() { char c; system(\ system(\ do{ system(\ }

printf(\ 航空客运订票系统主菜单\\n\

printf(\

printf(\ 1.航班管理菜单\\n\ printf(\ 2.订票办理菜单\\n\ printf(\ 3.退票办理菜单\\n\ printf(\ 4.乘客管理菜单\\n\ printf(\ 5.退出系统\\n\ printf(\谢谢使用航空客运订票系统********************\\n\ printf(\请选择您想要的服务:\ scanf(\ switch(c) { case'1':LinemanageMenu();break; case'2':bookingMenu();break; case'3':RefundticketMenu();break; case'4':CustomermagMenu();break; case'5':exit(0); default:break; }

}while(c!='5');

本文来源:https://www.bwwdw.com/article/cc9.html

Top