VC++航空订票系统数据库设计 第4页
char Des[10];
int i=2;
while (i!=1)
{
cout<<"请输入目的地:"<<endl;
cin>>Des;
p=head;
while (p->next&&strcmp(p->next->Des,Des))
{
p=p->next;
}
q=p->next;
if (q==NULL)
{
cout<<"对不起不存在此航班"<<endl;
}
else
{
while(i!=1)
{
cout<<"输入需要够买的票数"<<endl;
cin>>Ticket_Amount;
while(Ticket_Amount==0)
{
cout<<"请输入一个非零数:"<<endl;
cin>>Ticket_Amount;
}
if (Ticket_Amount<=q->FreeTicket)
{
BuyTicket(q,Ticket_Amount);
//买票,详细介绍见下文
}
else
{
int n;
cout<<"剩余票数小于定票数,是否需要列入候补名单?(1、是 2、否)"<<endl;
cin>>n;
Buyreplace(q,Ticket_Amount,n);
//进入替补名单,详细介绍见下文
}
cout<<"1、返回主菜单 2、继续"<<endl;
cin>>i;
}
}
}
}
7. FlightCancelTicket()——退票
作为人性化的航空客运订票系统,不但要实现订票,还要实现退票。在退票方面,仍旧是利用链表,将乘客信息删除。但删除之后,如若有替补乘客,还要使其依照进入替补乘客的队列的次序出队来实现订票。其具体实现代码如下:
void FlightCancelTicket() //退票
{
void BuyTicket(PFlight ,int );
Flight *p,*q;
Customer *h,*j;
char FlightNum[6];
char Customer_Name[10];
int Replace1_Amount; //候补第一个人的定票数
int i;
while (i!=1)
{
cout<<"请输入需要退定的航班号:"<<endl;
cin>>FlightNum;
p=head;
while (p->next&&strcmp(p->next->FlightNum,FlightNum))
{
p=p->next;
}
q=p->next;
if (q==NULL)
{
cout<<"对不起不存在此航班"<<endl;
}
else
{
while (i!=2)
{
cout<<"请输入姓名:"<<endl;
cin>>Customer_Name;
h=q->CustName;
while (h->next&&strcmp(h->next->Name,Customer_Name))
{
h=h->next;
}
j=h->next;
if(j==NULL)
{
cout<<"查无此人"<<endl;
}
else
{
if(j->next==NULL){ //当删除最后一个结点
Cusrear=h;
}
h->next=h->next->next;
q->FreeTicket+=j->Amount;
delete j;
cout<<"删除成功!"<<endl;
if(q->ReplName->next!=NULL)
{
Replace1_Amount=q->ReplName->next->Amount;
if (Replace1_Amount<=q->FreeTicket)
{
Replace *rep;
rep=q->ReplName->next;
Customer *Cus2;
Cus2=new Customer;
Cus2->SeatNum=q->Ration-q->FreeTicket+1;
strcpy(Cus2->FlightNum, q->FlightNum );
strcpy(Cus2->Name, rep->Name );
Cus2->Amount=rep->Amount;
Cus2->Level=rep->Level;
cout<<"乘客"<<rep->Name<<"已经成功买票 "<<endl;
cout<<"座位号为:";
for(int i=1;i<=(rep->Amount);i++)
{
cout<<Cus2->SeatNum++<<" ";
}
cout<<endl;
if (q->CustName->next==NULL)
{
Cusrear=q->CustName;
Cusrear->next=Cus2;
Cusrear=Cus2;
Cusrear->next=NULL;
}
else
{
Cusrear->next=Cus2;
Cusrear=Cus2;
Cusrear->next=NULL;
}
上一页 [1] [2] [3] [4] [5] [6] 下一页