航空客运订票系统.docx
《航空客运订票系统.docx》由会员分享,可在线阅读,更多相关《航空客运订票系统.docx(20页珍藏版)》请在冰豆网上搜索。
航空客运订票系统
课程设计报告:
航空客运订票系统
题目:
航空客运订票系统
班级:
姓名
学号:
完成日期:
2010-7-5
一、课程设计内容
航空客运订票的业务活动包括:
查询航线、客票预订和办理退票等。
试设计一个航空客运订票系统,以使上述业务可以借助计算机来完成。
二、需求分析
(1)每条航线所涉及的信息有:
终点站名、航班号、飞机号、飞行周日(星期几)、乘员定额、余票量、已订票的客户名单(包括姓名、订票量、舱位等级1,2或3)以及等候替补的客户名单(包括姓名、所需票量);
(2)系统能实现的操作和功能如下:
①录入:
可以录入航班情况,全部数据可以只放在内存中,最好存储在文件中;
②查询航线:
根据旅客提出的终点站名输出下列信息:
航班号、飞机号、星期几飞行,最近一天航班的日期和余票额;
③承办订票业务:
根据客户提出的要求(航班号、订票数额)查询该航班票额情况,若尚有余票,则为客户办理订票手续,输出座位号;若已满员或余票额少于订票额,则需重新询问客户要求。
若需要,可登记排队候补;
④承办退票业务:
根据客户提供的情况(日期、航班),为客户办理退票手续,然后查询该航班是否有人排队候补,首先询问排在第一的客户,若所退票额能满足他的要求,则为他办理订票手续,否则依次询问其他排队候补的客户。
三、概要设计
系统结构图
四、源程序
详细代码:
#include
#include
#include
#include
#definem4//3架飞机
#definen5//每架飞机5张票
structnode
{charname[21];
charid[21];
intseat,plane,date;
node*next,*pre;
};
structwait
{
charname[21];
charid[21];
charphone[8];
intseat,plane,date,count;
wait*next,*pre;
};
structpiao
{
intseat[n+1];
};
voidmakenull();
voidmakenull_piao();
voidmakenull_information();
voidlist_menu();
voidlist_piao();
voidmakenull_wait();
voidlist_information();
voidplane_information(node*head);
voidbook();
voidadd_information(node*head,intx,inty);
voidadd_wait(intx,inty);
voidsearch_delete(intx);
voidwrite_to_file();
voidshow_wait();
boolcomp(node*x,node*y);
node*head1,*head2,*head3,*q;
wait*wait_head,*wait_end;
charc;
piaoa[m];
voidmain()
{
makenull();
do
{list_menu();
cout<";
cin>>c;
if(c!
='6')
switch(c)
{
case'0':
show_wait();break;
case'1':
{list_piao();book();}break;
case'2':
search_delete
(1);break;
case'3':
list_piao();break;
case'4':
list_information();break;
case'5':
search_delete(0);break;
default:
break;
}
}while(c!
='6');
cout<<"ExitSystem";
}
voidmakenull()
{
makenull_piao();
makenull_information();
makenull_wait();
}
voidlist_menu()
{cout<cout<cout<cout<cout<cout<cout<cout<cout<cout<cout<cout<}
voidmakenull_piao()
{
FILE*fp;
inti;
if((fp=fopen("piao.dat","r"))==NULL)
{
fp=fopen("piao.dat","w");
for(i=1;i<=m-1;i++)
fwrite(&a[i],sizeof(piao),1,fp);
fclose(fp);
fp=fopen("piao.dat","r");
}
for(i=1;i<=m-1;i++)
fread(&a[i],sizeof(piao),1,fp);
fclose(fp);
}
voidmakenull_information()
{
node*r;
FILE*fp;
inti,j,sum;
sum=a[1].seat[0]+a[2].seat[0]+a[3].seat[0];
fp=fopen("information.dat","r");
head1=newnode;
head2=newnode;
head3=newnode;
head1->pre=NULL;
head1->next=NULL;
head2->pre=NULL;
head2->next=NULL;
head3->pre=NULL;
head3->next=NULL;
q=head1;
for(i=1;i<=sum;i++)
{
j=0;
r=newnode;
fread(r,sizeof(node),1,fp);
q->next=r;
r->pre=q;
r->next=NULL;
q=q->next;
fclose(fp);
if(i==a[1].seat[0]+1){
head2->next=q;
q->pre->next=NULL;
q->pre=head2;
}
if(i==a[1].seat[0]+a[2].seat[0]+1){
head3->next=q;
q->pre->next=NULL;
q->pre=head3;
}
}
}
voidmakenull_wait()
{
wait*tempw;
FILE*fp;
tempw=newwait;
inti;
if((fp=fopen("wait.txt","r"))==NULL)
{
fp=fopen("wait.txt","w");
fclose(fp);
}
wait_end=newwait;
wait_head=newwait;
wait_end->next=NULL;
wait_end->pre=NULL;
wait_head=wait_end;
wait_head->count=0;
fp=fopen("wait.txt","r");
fread(wait_head,sizeof(wait),1,fp);
for(i=1;i<=wait_head->count;i++)
{
fread(tempw,sizeof(wait),1,fp);
wait_end->next=tempw;
tempw->pre=wait_end;
tempw->next=NULL;
wait_end=tempw;
}
}
voidlist_piao()
{
inti,j;
for(i=1;i<=m-1;i++)
{
if(a[i].seat[0]!
=n)
{
cout<"<for(j=1;j<=n;j++)
if(a[i].seat[j]==0)cout<<""<cout<}
elsecout<"<}
}
voidlist_information()
{
intx;
do{cout<";cin>>x;cout<=m);
cout<if(x==1)plane_information(head1);
if(x==2)plane_information(head2);
if(x==3)plane_information(head3);
}
voidplane_information(node*head)
{
node*q;
charch;
intx=0;
if(head!
=NULL&&head->next!
=NULL)
q=head->next;
else{
q=NULL;
cout<<"飞机空,无预订票!
"<}
while(q!
=NULL)
{
cout<q->date=q->plane;
cout<<"日期:
"<date<cout<<"座位号:
"<seat<cout<<"姓名:
"<name;
cout<"<id;
q=q->next;x++;
if(x%3==0)ch=getch();
}
cout<}
voidbook()
{
inti,j,p;
cout<(1、2、3)";
do{
cin>>i;
if(i<1||i>=m){
cout<****"<";
}
else
{cout<cout<"<for(p=1;p<=n;p++)
if(a[i].seat[p]==0)cout<<""<
cout<break;}
}while
(1);
cout<";
do{
cin>>j;
if(j<1||j>n){
cout<****"<";
}
else
{
q->date=i;
cout<"<date<break;
}
}while
(1);
if(a[i].seat[j]==0){
a[i].seat[j]=1;
cout<a[i].seat[0]++;
if(i==1)add_information(head1,1,j);
if(i==2)add_information(head2,2,j);
if(i==3)add_information(head3,3,j);
}
else
{cout<add_wait(i,j);
}
}
voidadd_wait(intx,inty)
{
wait*tempw;
tempw=newwait;
tempw->next=NULL;
cout<<"请输入个人信息"<cout<cout<<"姓名:
";cin>>tempw->name;
cout<<"ID号:
";cin>>tempw->id;
cout<<"电话:
";cin>>tempw->phone;
tempw->seat=y;
tempw->plane=x;
wait_end->next=tempw;
tempw->pre=wait_end;
wait_end=wait_end->next;
cout<wait_head->count++;
write_to_file();
}
voidshow_wait()
{
wait*tempw;
tempw=wait_head->next;
if(tempw==NULL)cout<"<while(tempw!
=NULL)
{
cout<name<<"-";
tempw=tempw->next;
}
}
voidadd_information(node*head,intx,inty)
{
node*temp;
temp=newnode;
temp->pre=NULL;
temp->next=NULL;
cout<<"请输入个人信息"<cout<cout<<"姓名:
";cin>>temp->name;
cout<<"ID号:
";cin>>temp->id;
temp->seat=y;
temp->plane=x;
temp->next=head->next;
temp->pre=head;
if(head->next!
=NULL)head->next->pre=temp;
head->next=temp;
write_to_file();
cout<}
voidsearch_delete(intx)
{
node*p,*q,*r;
wait*tempw,*tempw2,*tempw3;
intstep=1,t1,t2,i;
charch;
p=newnode;
tempw=newwait;
tempw2=newwait;
tempw3=newwait;
q=head1;
cout<cout<<"*************"<cout<";cin>>p->name;
do{
q=q->next;
if((q!
=NULL)&&
(comp(q,p)))
{
cout<q->date=q->plane;
cout<<"Located!
"<cout<<"****************";
cout<"<name;
cout<"<id;
cout<"<seat;
cout<"<plane;
cout<"<date<if(x==1){
cout<<"删除该纪录?
[Y/N]";
cin>>ch;
if(ch=='Y'||ch=='y'){
t1=q->plane;
t2=q->seat;
a[t1].seat[t2]=0;
a[t1].seat[0]--;
r=q;q=q->pre;
r->pre->next=r->next;
if(r->next!
=NULL)r->next->pre=r->pre;
delete(r);
cout<<"****记录删除成功!
****";
write_to_file();
tempw=wait_head;
for(i=0;icount;i++)
{
tempw=tempw->next;
if(tempw==NULL)break;
if((tempw->plane==t1)&&(tempw->seat==t2))
{
strcpy(tempw3->name,tempw->name);
strcpy(tempw3->phone,tempw->phone);
cout<"<cout<"<name;
cout<"<id<a[t1].seat[0]++;
a[t1].seat[t2]=1;
if(tempw->plane==1)add_information(head1,1,tempw->seat);
if(tempw->plane==2)add_information(head2,2,tempw->seat);
if(tempw->plane==3)add_information(head3,3,tempw->seat);
tempw2=tempw->pre;
tempw2->next=tempw->next;
if(tempw->next==NULL)wait_end=tempw2;
elsetempw->next->pre=tempw2;
delete(tempw);
wait_head->count--;
write_to_file();
cout<name<<"已经成功订票,已经由电话"<phone<<"通知了"<break;
}
}
}
}continue;
}
else
{
if(q==NULL)
{
step++;
if(step==2)q=head2;
if(step==3)q=head3;
if(step==4){cout<}
}
}while
(1);
}
boolcomp(node*x,node*y)
{
node*p,*q;
inti,j,k;
p=x;
q=y;
i=j=0;
do
{
while((p->name[i]!
=q->name[j])&&(p->name[i]!
='\0'))i++;
if(p->name[i]=='\0'){return(false);break;}
else
{
k=i;
while((p->name[k]==q->name[j])&&(q->name[j]!
='\0')){k++;j++;}
if(q->name[j]=='\0')return(true);
else
{
j=0;
i++;
}
}
}while((q->name[j]!
='\0')&&(p->name[i]!
='\0'));
return(false);
}
voidwrite_to_file()
{
FILE*fp;
inti,j;
intx[m];
node*p;
wait*tempw;
tempw=newwait;
tempw=wait_head;
fp=fopen("piao.dat","w");
for(i=1;i<=m-1;i++)
{
fwrite(&a[i],sizeof(piao),1,fp);
}
fclose(fp);
fp=fopen("information.dat","w");
x[0]=0;x[1]=a[1].seat[0];
for(i=0,j=1;j<=m-1;j++){i=i+a[j].seat[0];x[j]=a[j].seat[0]+x[j-1];}
j=1;p=head1->next;
for(j=1;j<=i;j++)
{
if(j==x[1]+1)p=head2->next;
if(j==x[2]+1)p=head3->next;
if(p==NULL)break;
fwrite(p,sizeof(node),1,fp);
p=p->next;
}
fclose(fp);
fp=fopen("wait.txt","w");
for(j=0;j<=wait_head->count;j++)
{
if(tempw==NULL)break;
fwrite(tempw,sizeof(wait),1,fp);
tempw=tempw->next;
}
fclose(fp);
五、测试数据及程序运行情况
主界面
查看飞机信息
订票
查询乘客信息
退票
余票不足
实验过程中出现的问题及解决方法:
1、一开始错误很多,包括大量的语法错误和逻辑错误。
通过反复的编译、学习和修改,更正了程序中的语法,使程序可以正常编译,运行。
2、程序健壮性方面屡屡遇到问题,在程序的测试过程中逐步发现并改进,如主菜单选择