航空客运订票系统源代码.docx

上传人:b****5 文档编号:11851215 上传时间:2023-04-06 格式:DOCX 页数:22 大小:19.87KB
下载 相关 举报
航空客运订票系统源代码.docx_第1页
第1页 / 共22页
航空客运订票系统源代码.docx_第2页
第2页 / 共22页
航空客运订票系统源代码.docx_第3页
第3页 / 共22页
航空客运订票系统源代码.docx_第4页
第4页 / 共22页
航空客运订票系统源代码.docx_第5页
第5页 / 共22页
点击查看更多>>
下载资源
资源描述

航空客运订票系统源代码.docx

《航空客运订票系统源代码.docx》由会员分享,可在线阅读,更多相关《航空客运订票系统源代码.docx(22页珍藏版)》请在冰豆网上搜索。

航空客运订票系统源代码.docx

航空客运订票系统源代码

航空客运订票系统源代码

#include//dos控制命令头文件

#include//输入输出头文件

#include//控制格式头文件

#include//getchar()用到

#include//字符串函数

usingnamespacestd;//标准命名空间

#defineOK1//函数结果状态码

#defineERROR0//函数结果状态码

#defineTRUE1//函数结果状态码

#defineFALSE0//函数结果状态码

typedefintstatus;//函数结果状态码

staticintcusnum=1;//顾客数(全局变量)

staticintairnum=1;//航线数(全局变量)

//顾客结构体

structcustomer{

charname[9];//顾客名

charline_num[8];//航班号

intpiaonum;//座位号

structcustomer*next;//下一个结点

};

typedefcustomer*Linkcustomer;

//候补顾客结构体

typedefstructhoubuNode{//候补顾客结构体

charname[9];//姓名

charend_place[10];//终点站

intpnum;//票数

structhoubuNode*next;//指针域

}*houbucustomer;

structLinkQueue

{

houbucustomerfront,rear;//队头队尾指针

};

//航线结构体

structairline{

charline_num[8];//航班号

charplane_num[8];//飞机号

charend_place[20];//目的的

charfly_data[20];//飞行周日

inttotal;//座位总数

intleft;//剩余座位

Linkcustomercustom;//订票顾客指针

LinkQueuehoubucus;//候补顾客指针

structairline*next;//下一个结点

};

typedefairline*Linkairline;

//初始化航线链表

voidinit_airline(Linkairline&l){

l=newairline[sizeof(airline)];//产生头结点,并始l指向此头结点

if(!

l){//存储分配失败

exit(0);//退出

}

l->next=NULL;//头结点的指针域为空

}

//初始化顾客链表(同初始化航线链表)

voidinit_customer(Linkcustomer&l){

l=newcustomer[sizeof(customer)];

if(!

l){

exit(0);

}

l->next=NULL;

}

//初始化候补顾客队列链表(同初始化航线链表)

voidinit_houbucustomer(LinkQueue&Q){

Q.front=Q.rear=newhoubuNode[sizeof(houbuNode)];//

if(!

Q.front){

exit(0);

}

Q.front->next=NULL;

}

//判断airline链表是否为空

statusairLineEmpty(LinkairlineL)

{

if(L->next)//非空

returnFALSE;

else

returnTRUE;

}

//airline链表插入操作

statusinsert_airline(LinkairlineL,inti,char*line_num,char*plane_num,char*end_place,char*fly_data,inttotal,intleft,Linkcustomercustom,LinkQueuehoubucus){

intj=0;//计数器

Linkairlines,p=L;//p指向头结点

while(p&&j

{

j++;

p=p->next;

}

if(!

p||j>i-1)//i小于1或大于表长

returnERROR;//插入失败

s=newairline[sizeof(airline)];//生成新结点

strcpy(s->line_num,line_num);//给新结点赋值

strcpy(s->plane_num,plane_num);

strcpy(s->end_place,end_place);

strcpy(s->fly_data,fly_data);

s->total=total;

s->left=left;

s->custom=custom;

s->houbucus=houbucus;

s->next=p->next;//新结点指向原第i个结点

p->next=s;//原第i-1个结点指向新结点

returnOK;//插入成功

}

//customer链表插入操作(同airline链表插入操作)

statusinsert_customer(LinkcustomerL,inti,char*name,char*line_num,intpiaonum){

intj=0;

Linkcustomers,p=L;

while(p&&j

{

j++;

p=p->next;

}

if(!

p||j>i-1)

returnERROR;

s=newcustomer[sizeof(customer)];

strcpy(s->name,name);

strcpy(s->line_num,line_num);

s->piaonum=piaonum;

s->next=p->next;

p->next=s;

returnOK;

}

//houbucustomer入队操作

voidinsert_houbucustomer(LinkQueue&Q,char*name,char*end_place,intpnum){

houbucustomerp;

p=newhoubuNode[sizeof(houbuNode)];

strcpy(p->name,name);

strcpy(p->end_place,end_place);

p->pnum=pnum;

p->next=NULL;

Q.rear->next=p;

Q.rear=p;

}

//houbucustomer出队操作

statusdel_houbucustomer(LinkQueue&Q,houbuNode&hbnode){

houbucustomerp;

p=Q.front->next;

strcpy(hbnode.name,p->name);

strcpy(hbnode.end_place,p->end_place);

hbnode.pnum=p->pnum;

Q.front->next=p->next;

if(Q.rear==p)

Q.rear=Q.front;

deletep;

returnOK;

}

//houbucustomer输出操作

voidprint_houbucustomer(LinkQueueQ)

{

houbucustomerp=Q.front->next;

cout<<"候补顾客为:

"<

cout<<"姓名终点站票数"<

while(p)

{

cout<name<<""<end_place<<""<pnum;

p=p->next;

}

cout<

}

//打印航线信息

statusprint_airline(Linkairlinel)

{

cout<

Linkairlinep=l->next;

for(;p!

=NULL;p=p->next)

{

cout<

:

left)<

cout<line_num<plane_num<end_place

<fly_data<total<left<<

setw(12)<<&(p->houbucus)<custom)<

}

returnOK;

}

//打印航线信息(print_airline重载)

statusprint_airline(Linkairlinel,stringname,intN)

{

stringinfo;

boolflag=true;

Linkairlinep=l->next;

for(;p!

=NULL;p=p->next)

{

if(N==1)

info=p->end_place;

else

info=p->line_num;

if(info==name)

{

flag=false;

cout<

cout<

:

left)<

cout<line_num<plane_num<end_place

<fly_data<total<left<<

setw(12)<<&(p->custom)<houbucus)<

break;

}

}

if(flag)

{

if(N==1)

cout<<"对不起,没有终点站为"<

else

cout<<"对不起,没有航班号为"<

}

returnOK;

}

//打印顾客信息

statusprint_customer(Linkcustomerl)

{

Linkcustomerp=l->next;

for(;p!

=NULL;p=p->next)

{

cout<

:

left);//输出格式控制

cout<name<line_num<piaonum<

}

returnOK;

}

//航班信息录入

statusaddmoreairline(Linkairlinel,Linkcustomercustom,LinkQueuehoubucus)

{

charline_num1[8],plane_num1[8],fly_data1[8],end_place1[8];

inttotal1=100,left1=80;

cout<<"请输入以下信息:

"<

cout<<"航班号:

";

cin>>line_num1;

cout<<"飞机号:

";

cin>>plane_num1;

cout<<"目的地:

";

cin>>end_place1;

cout<<"飞行周日:

";

cin>>fly_data1;

cout<<"总票数:

";

cin>>total1;

cout<<"余票数:

";

cin>>left1;

insert_airline(l,airnum,line_num1,plane_num1,end_place1,fly_data1,total1,left1,custom,houbucus);

airnum++;

cout<<"添加成功!

"<

print_airline(l);

returnOK;

}

//修改airline链表中的数据

statusmodefy_airline(Linkairlinel,char*line_num)

{

Linkairlinep=l->next;

for(;p!

=NULL;p=p->next)

{

if(strcmp(line_num,p->line_num)==0)

{

p->left++;

returnOK;

}

}

cout<<"没有这个航班,无法完成修改任务!

"<

returnERROR;

}

//订票

statusbook(Linkairlinel,char*end_place,Linkcustomerc,char*name,

intnum,LinkQueuehoubu)

{

Linkairlinep=l->next;//p指向第一个结点

Linkcustomerq=c->next;//q指向第一个结点

for(;p!

=NULL;p=p->next)//查找

{

if(strcmp(end_place,p->end_place)==0)

{

if(p->left-num>=0)//剩余票数大于订票数

{

cout<<"订票成功!

"<

insert_customer(c,cusnum,name,p->line_num,num);//向顾客链表插入记录

p->left-=num;//订票成功,剩余票数减少

cusnum++;//顾客数加一

returnOK;

}

else//剩余票数小于订票数

{

charpd;

cout<<"对不起,余票不足!

"<

cout<<"是否需要排队候补(Y/N):

";

cin>>pd;

if(pd=='Y'||pd=='y')//需要排队候补

{

insert_houbucustomer(houbu,name,end_place,num);//向候补队列插入记录

cout<<"候补登记成功!

"<

print_houbucustomer(houbu);

}

else

{}

}

return0;

}

}

cout<<"对不起,没有终点站为"<

"<

returnERROR;

}

//退票

statusdelete_cus(Linkcustomerh,Linkairlinel,char*name,LinkQueuehoubu)

{

Linkcustomerp=h->next,pr=h;//p指向顾客链表首结点

charline_num[8];

houbuNodehbnode;

while(p!

=NULL)//循环查找退票顾客

{

if(strcmp(name,p->name)==0)

{

strcpy(line_num,p->line_num);

for(inti=0;ipiaonum;i++)//更改该航线的剩余票数

modefy_airline(l,line_num);

pr->next=p->next;

cout<<"顾客"<name<<"退票成功!

"<

cusnum--;//顾客数减一

if(houbu.front->next==NULL)

{

}

else

{

del_houbucustomer(houbu,hbnode);//候补顾客出队

if(l->next->left>=hbnode.pnum)//剩余票数多于排在第一位的客户订的票数

{

//为排在第一位的客户办理订票业务

book(l,hbnode.end_place,h,hbnode.name,hbnode.pnum,houbu);

cout<<"候补顾客"<

"<

}

else//剩余票数少于排在第一位的客户订的票数

{

cout<<"票数仍然不足!

";

}

}

returnOK;

}

pr=pr->next;

p=pr->next;

}

cout<<"无此顾客,无法退票!

"<

returnERROR;

}

//打开进度条,程序信息简介

voidopen()

{

cout<<"\n\n\n\n课程设计\n";

cout<<"\n╔-------------------------------╗";

cout<<"\n││";

cout<<"\n│名称:

航空订票系统│";

cout<<"\n││";

cout<<"\n│作者:

乐升平│";

cout<<"\n││";

cout<<"\n│学号:

6│";

cout<<"\n││";

cout<<"\n│班级:

12计科

(2)班│";

cout<<"\n││";

cout<<"\n│工具:

VC++6.0C++语言│";

cout<<"\n││";

cout<<"\n╚-------------------------------╝\n";

system("pause");

system("cls");

cout<<"\n\n\n\n\n\n****************欢迎使用航空订票系统**************\n\n\n";

constintM=25;

intk;

cout<<"\n〓程序加载中>>>>";

for(k=1;k<=M;k++)

{

cout<<"■";

Sleep(100);

}

system("cls");

cout<

cout<<"前言"<

cout<<"欢迎使用『航空订票系统』,本程序实现了以下功能:

\n\n";

cout<<"①录入功能:

可以录入航班情况\n\n";

cout<<"②查询功能:

根据客户提供的终点站名或航班号进行查询。

\n\n";

cout<<"③订票功能:

根据客户提出的要求及实际情况为客户办理订票手续,且跟据需要\n\n";

cout<<"可登记排队候补。

\n\n";

cout<<"④退票功能:

根据客户提供的情况为客户办理退票手续,若有候补订票顾客还可\n\n";

cout<<"为排在第一位的客户办理订票手续。

\n\n";

system("pause");

system("cls");

}

//主函数

intmain()

{

open();

charchoice,name[9],end_place[10];

intt=1,num;

Linkairlineair;

Linkcustomercustomer;

LinkQueuehoubu;

init_airline(air);//初始化airline链表

init_customer(customer);//初始化customer链表

init_houbucustomer(houbu);//初始化houbucustomer队列

while(t==1)//进入菜单

{

system("cls");

cout<<"\n\n****************欢迎使用航空订票系统***************\n\n";

cout<<"请选择菜单\n\n";

cout<<"1录入\n\n";

cout<<"2订票\n\n";

cout<<"3退票\n\n";

cout<<"4查询\n\n";

cout<<"0退出\n\n";

cout<<"请选择:

";

cin>>choice;

switch(choice)

{

case'1':

{//航班信息录入

system("cls");

addmoreairline(air,customer,houbu);//录入航班信息

system("pause");

break;

}

case'2':

{//订票

system("cls");

if(airLineEmpty(air))//订票前航班信息为空

{

cout<<"ERROR!

请先输入航线信息!

"<

}

else

{

cout<<"请输入你要订的终点站名:

";

cin>>end_place;

cout<<"请输入你的姓名:

";

cin>>name;

cout<<"请输入你的订票数量:

";

cin>>num;

book(air,end_place,customer,name,num,h

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 成人教育 > 电大

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1