数据结构航空客运订票系统方案Word文件下载.docx
《数据结构航空客运订票系统方案Word文件下载.docx》由会员分享,可在线阅读,更多相关《数据结构航空客运订票系统方案Word文件下载.docx(32页珍藏版)》请在冰点文库上搜索。
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<
<
endl<
"
chooseanoperation:
"
;
cin>
>
c;
if(c!
='
6'
)
switch(c)
{
case'
0'
:
show_wait();
break;
1'
{list_piao();
book();
}break;
2'
search_delete
(1);
3'
list_piao();
4'
list_information();
5'
search_delete(0);
default:
break;
}
}while(c!
);
ExitSystem"
}
voidmakenull()
makenull_piao();
makenull_information();
makenull_wait();
voidlist_menu()
{cout<
菜单"
************************"
*0.查看排队情况*"
*1.订票*"
*2.退票*"
*3.查看剩余票*"
*4.查看飞机信息*"
*5.查看乘客信息*"
*6.退出*"
voidmakenull_piao()
FILE*fp;
inti;
if((fp=fopen("
piao.dat"
"
r"
))==NULL)
fp=fopen("
w"
for(i=1;
i<
=m-1;
i++)
fwrite(&
a[i],sizeof(piao),1,fp);
fclose(fp);
for(i=1;
fread(&
voidmakenull_information()
node*r;
inti,j,sum;
sum=a[1].seat[0]+a[2].seat[0]+a[3].seat[0];
information.dat"
head1=newnode;
head2=newnode;
head3=newnode;
head1->
pre=NULL;
next=NULL;
head2->
head3->
q=head1;
=sum;
j=0;
r=newnode;
fread(r,sizeof(node),1,fp);
q->
next=r;
r->
pre=q;
q=q->
next;
if(i==a[1].seat[0]+1){
next=q;
pre->
pre=head2;
if(i==a[1].seat[0]+a[2].seat[0]+1){
pre=head3;
voidmakenull_wait()
wait*tempw;
tempw=newwait;
wait.txt"
))==NULL)
wait_end=newwait;
wait_head=newwait;
wait_end->
wait_head=wait_end;
wait_head->
count=0;
fread(wait_head,sizeof(wait),1,fp);
=wait_head->
count;
fread(tempw,sizeof(wait),1,fp);
next=tempw;
tempw->
pre=wait_end;
wait_end=tempw;
voidlist_piao()
inti,j;
if(a[i].seat[0]!
=n)
第"
架飞机剩余的票:
endl;
for(j=1;
j<
=n;
j++)
if(a[i].seat[j]==0)cout<
j;
elsecout<
The"
planeisfull!
voidlist_information()
intx;
do{cout<
显示哪架飞机的信息?
x;
cout<
}while(x<
1||x>
=m);
x<
架飞机的信息如下"
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->
else{
q=NULL;
飞机空,无预订票!
while(q!
*******************"
date=q->
plane;
日期:
q->
date<
座位号:
seat<
name;
ID号:
id;
x++;
if(x%3==0)ch=getch();
voidbook()
inti,j,p;
请选择地点:
(1、2、3)"
do{
i;
if(i<
1||i>
=m){
****超出围!
****"
请重新输入:
else
{cout<
你要订的是到"
地的飞机"
for(p=1;
p<
p++)
if(a[i].seat[p]==0)cout<
p;
}while
(1);
请选择座位号:
if(j<
1||j>
n){
date=i;
您的订票日期:
}while
(1);
if(a[i].seat[j]==0){
a[i].seat[j]=1;
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)
请输入个人信息"
*************"
cin>
tempw->
ID号:
phone;
seat=y;
plane=x;
wait_end=wait_end->
****正在排队等候****"
count++;
write_to_file();
voidshow_wait()
tempw=wait_head->
if(tempw==NULL)cout<
排队中没有人!
while(tempw!
=NULL)
name<
-"
tempw=tempw->
voidadd_information(node*head,intx,inty)
node*temp;
temp=newnode;
temp->
temp->
next=head->
pre=head;
if(head->
=NULL)head->
next->
pre=temp;
next=temp;
****订票成功****"
voidsearch_delete(intx)
node*p,*q,*r;
wait*tempw,*tempw2,*tempw3;
intstep=1,t1,t2,i;
p=newnode;
tempw2=newwait;
tempw3=newwait;
p->
do{
if((q!
=NULL)&
(comp(q,p)))
Located!
****************"
seat;
班机号:
if(x==1){
删除该纪录?
[Y/N]"
ch;
if(ch=='
Y'
||ch=='
y'
){
t1=q->
t2=q->
a[t1].seat[t2]=0;
a[t1].seat[0]--;
r=q;
q=q->
pre;
next=r->
if(r->
=NULL)r->
pre=r->
delete(r);
****记录删除成功!
****"
tempw=wait_head;
for(i=0;
wait_head->
if(tempw==NULL)break;
if((tempw->
plane==t1)&
(tempw->
seat==t2))
strcpy(tempw3->
name,tempw->
name);
phone,tempw->
phone);
等候的人中有可以订票的了:
id<
a[t1].seat[0]++;
a[t1].seat[t2]=1;
if(tempw->
plane==1)add_information(head1,1,tempw->
seat);
plane==2)add_information(head2,2,tempw->
plane==3)add_information(head3,3,tempw->
tempw2=tempw->
tempw2->
next=tempw->
next==NULL)wait_end=tempw2;
elsetempw->
pre=tempw2;
delete(tempw);
count--;
等候的"
tempw3->
已经成功订票,已经由"
phone<
通知了"
}continue;
if(q==NULL)
step++;
if(step==2)q=head2;
if(step==3)q=head3;
if(step==4){cout<
****信息检索完毕****"
boolcomp(node*x,node*y)
node*p,*q;
inti,j,k;
p=x;
q=y;
i=j=0;
while((p->
name[i]!
=q->
name[j])&
(p->
='
\0'
))i++;
if(p->
name[i]=='
){return(false);
k=i;
name[k]==q->
(q->
name[j]!
)){k++;
j++;
if(q->
name[j]=='
)return(true);
i++;
}while((q->
)&
));
return(false);
voidwrite_to_file()
intx[m];
node*p;
x[0]=0;
x[1]=a[1].seat[0];
for(i=0,j=1;
j++){i=i+a[j].seat[0];
x[j]=a[j].seat[0]+x[j-1];
j=1;
p=head1->
=i;
j++)
if(j==x[1]+1)p=head2->
if(j==x[2]+1)p=head3->
if(p==NULL)break;
fwrite(p,sizeof(node),1,fp);
p=p->
for(j=0;
{
if(tempw==NULL)break;
fwrite(tempw,sizeof(wait),1,fp);