航空订票系统管理程序无法在DEVC++中编译,求高手、、、
#include <iostream.h>#include <process.h>
#include <string.h>
#include <conio.h>
#include <stdio.h>
#include <iomanip.h>
#include <fstream.h>
#define MAX 50
#define NULL 0
class Customer
{
public:
char Name[7]; //姓名
int Amount; //定票数
int Rank; //舱位等级
int Seat_No; //座位号
Customer *Next;
};
class Replace
{
public:
char Name[7]; //姓名
int Amount; //定票数
int Rank; //舱位等级
int Seat_No; //座位号
Replace *Next;
};
class Flight
{
public:
char Des_Name[10]; //终点站名
char Flight_No[6]; //航班号
char Plane_No[6]; //飞机号
int Week_Day; //飞行周日
int Customer_Amount; //乘员定额
int Free_Amount; //剩余票数
float Price[3]; //舱位等级的价格
Replace *ReplName; //该航班的候补乘客名单
Customer *CustName; //该航班的订票乘客名单
int CustNo; //该航班的已定票乘客数量
int ReplNo; //该航班的候补乘客数量
Flight *Next; //指示下一航线结点
};
int Customer_Count=0; //所有航线的定票乘客总数
Flight FL; //对象声明,用于文件写入时的引用
Flight *Head; //航线头指针
Flight *p2; //航线结点指针
Customer *Custp1[MAX]; //各条航线乘客结点指针
Customer CS; //对象声明,用于文件写入时的引用
Replace *Replp1[MAX]; //各条航线候补结点指针
Replace RP; //对象声明,用于文件写入时的引用
int IsEmpty=1; //是否有定票乘客
int IsReplace=1; //是否有候补乘客
Customer *prior; //满足要求的定票乘客的前结点,以作删除操作
//int Find_Line(Flight *,char *);
//int Find_Line(Flight *,char *,Flight &,int);
//void Line_See();
//---------------菜单模板函数---------------
char ModelMenu(char *s[],int Itemcount)
{
int i;
char choose;
system("cls");
cout<<" _ "<<endl;
cout<<" | / "<<endl;
cout<<" _| /______________________________________ "<<endl;
cout<<" - ______ ________________ /_/_`, "<<endl;
cout<<" -(_________ -======- ChinaAir ) "<<endl;
cout<<" `------=============----------------` "<<endl;
cout<<" ================================"<<endl;
cout<<" "<<s[0]<<endl;
cout<<" ================================"<<endl;
cout<<" "<<endl;
cout<<" ======================== "<<endl;
for(i=1;i<Itemcount;i++)
{
cout<<" "<<s[i]<<endl;
if(i+1!=Itemcount)
cout<<" ======================== "<<endl;
}
cout<<" ======================== "<<endl;
cout<<" ================================"<<endl;
cout<<" 请输入菜单项前的操作代码:";
cin>>choose;
return choose;
}
//---------------主菜单函数---------------
char MainMenu()
{
char *MenuItem[]=...{
"┊ 航空客运订票系统菜单 ┊",
" ┊ [1]. 订 票 办 理 ┊ ",
" ┊ [2]. 退 票 办 理 ┊ ",
" ┊ [3]. 航 线 管 理 ┊ ",
" ┊ [4]. 乘 客 管 理 ┊ ",
" ┊ [5]. 系 统 离 开 ┊ "
};
return ModelMenu(MenuItem,6);
}
//---------------是否继续函数---------------
char Continue()
{
char answer;
while(1)
{
cout<<" ";
cout<<"┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈";
cout<<" 是否继续(Y/N)?";
cin>>answer;
if(answer=='y'||answer=='Y')
return 'y';
else if(answer=='n'||answer=='N')
return 'n';
else
cout<<" 输入错误,请重新输入!"<<endl;
}
}
//---------------操作出错函数---------------
void ErrorMess()
{
cout<<" 对不起,没有相关菜单项,按任意键继续..."<<endl;
getch();
}
//--------------操作提示函数-------------
void prefix(char *Item)
{
system("cls");
cout<<" 当前操作:"<<Item<<endl;
cout<<" ";
cout<<"┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈";
cout<<endl;
}
//------------航线是否为空函数-------------
int Empty_Flight()
{
if(Head==NULL)
{
system("cls");
cout<<" 对不起,没有相关航线。按任意键返回..."<<endl;
getch();
return 1;
}
else
return 0;
}
//-----------------系统退出与保存-----------------
int ExitSystem()
{
char answer;
cout<<" 您确定要离开系统吗(Y/N)?";
cin>>answer;
system("cls");
int size1=sizeof(Flight);
int size2=sizeof(Customer);
int size3=sizeof(Replace);
fstream Write1,Write2,Write3;
Write1.open("Flight.txt",ios::binary|ios::app|ios::trunc);
Write2.open("Customer.txt",ios::binary|ios::app|ios::trunc);
Write3.open("Replace.txt",ios::binary|ios::app|ios::trunc);
Flight *p1;
Customer *p2;
Replace *p3;
p1=Head;
p2=p1->CustName;
p3=p1->ReplName;
if(answer=='y'||answer=='Y')
{
cout<<"航线信息写入......"<<endl;
while(p1!=NULL)
{
strcpy(FL.Des_Name,p1->Des_Name);
cout<<FL.Des_Name<<" ";
strcpy(FL.Flight_No,p1->Flight_No);
cout<<FL.Flight_No<<" ";
strcpy(FL.Plane_No,p1->Plane_No);
cout<<FL.Plane_No<<" ";
FL.Week_Day=p1->Week_Day;
cout<<FL.Week_Day<<" ";
FL.Customer_Amount=p1->Customer_Amount;
cout<<FL.Customer_Amount<<" ";
FL.Free_Amount=p1->Free_Amount;
cout<<FL.Free_Amount<<" ";
FL.Price[0]=p1->Price[0];
FL.Price[1]=p1->Price[1];
FL.Price[2]=p1->Price[2];
FL.CustNo=p1->CustNo;
cout<<FL.CustNo<<" ";
FL.ReplNo=p1->ReplNo;
cout<<FL.ReplNo<<endl;
Write1.write((char*)&FL,size1);
p1=p1->Next;
}
Write1.close();
cout<<"乘客信息写入......"<<endl;
p1=Head;
while(p1!=NULL)
{
if(p1->CustName!=NULL)
{
p2=p1->CustName;
while(p2!=NULL)
{
strcpy(CS.Name,p2->Name);
cout<<CS.Name<<" ";
CS.Rank=p2->Rank;
cout<<CS.Rank<<" ";
CS.Seat_No=p2->Seat_No;
cout<<CS.Seat_No<<" ";
CS.Amount=p2->Amount;
cout<<CS.Amount<<endl;
Write2.write((char*)&CS,size2);
p2=p2->Next;
}
}
p1=p1->Next;
}
Write2.close();
cout<<"候补信息写入......"<<endl;
p1=Head;
while(p1!=NULL)
{
if(p1->ReplName!=NULL)
{
p3=p1->ReplName;
while(p3!=NULL)
{
strcpy(RP.Name,p3->Name);
cout<<RP.Name<<" ";
RP.Rank=p3->Rank;
cout<<RP.Rank<<" ";
RP.Seat_No=p3->Seat_No;
cout<<RP.Seat_No<<" ";
RP.Amount=p3->Amount;
cout<<RP.Amount<<endl;
Write3.write((char*)&RP,size3);
p3=p3->Next;
}
}
p1=p1->Next;
}
Write3.close();
cout<<" 按任意键退出..."<<endl;
getch();
return 1;
}
else
return 0;
}
//-----------------从文件读取订票乘客信息-----------------
void AccessReserve()
{
int size=sizeof(Customer);
fstream Access("Customer.txt",ios::binary|ios::in);
Access.seekg(0,ios::beg);
Flight *p1;
Customer *p2;
p1=Head;
int Flight_No=0;
while(p1!=NULL)
{
// cout<<"该航线乘客总数"<<p1->CustNo;
if(p1->CustNo!=0)
{
IsEmpty=0;
p2=p1->CustName;
// cout<<"票"<<CS.Amount;
for(int i=0;i<p1->CustNo;i=i+CS.Amount)
{
Access.read((char*)&CS,sizeof(Customer));
if(p1->CustName==NULL)
{
Custp1[Flight_No]=p2=new Customer;
p1->CustName=Custp1[Flight_No];
// cout<<"线"<<p1->Flight_No;
}
else
{
p2=new Customer;
Custp1[Flight_No]->Next=p2;
Custp1[Flight_No]=p2;
// cout<<"线"<<p1->Flight_No;
}
strcpy(Custp1[Flight_No]->Name,CS.Name);
// cout<<Custp1[Flight_No]->Name;
Custp1[Flight_No]->Amount=CS.Amount;
// cout<<Custp1[Flight_No]->Amount;
Custp1[Flight_No]->Rank=CS.Rank;
// cout<<Custp1[Flight_No]->Rank;
Custp1[Flight_No]->Seat_No=CS.Seat_No;
// cout<<Custp1[Flight_No]->Seat_No;
p2=p2->Next;
}
Custp1[Flight_No]->Next=NULL;
}
p1=p1->Next;
Flight_No++;
}
Access.close();
}
//-----------------从文件读取候补乘客信息-----------------
void AccessReplace()
{
int size=sizeof(Replace);
fstream Access("Replace.txt",ios::binary|ios::in);
Access.seekg(0,ios::beg);
Flight *p1;
Replace *p2;
p1=Head;
while(p1!=NULL)
{
// cout<<"乘客数"<<p1->CustNo;
// cout<<"候补数"<<p1->ReplNo;
int Flight_No=0;
if(p1->ReplNo!=0)
{
IsEmpty=0;
IsReplace=0;
p2=p1->ReplName;
for(int i=0;i<p1->ReplNo;i=i+RP.Amount)
{
// cout<<i;
Access.read((char*)&RP,sizeof(Replace));
if(p1->ReplName==NULL)
{
Replp1[Flight_No]=p2=new Replace;
p1->ReplName=Replp1[Flight_No];
// cout<<"所在航线"<<p1->Des_Name;
}
else
{
p2=new Replace;
Replp1[Flight_No]->Next=p2;
Replp1[Flight_No]=p2;
// cout<<"线"<<p1->Des_Name;
}
strcpy(Replp1[Flight_No]->Name,RP.Name);
// cout<<"名"<<Replp1[Flight_No]->Name;
Replp1[Flight_No]->Amount=RP.Amount;
// cout<<"数"<<Replp1[Flight_No]->Amount;
Replp1[Flight_No]->Rank=RP.Rank;
// cout<<"等"<<Replp1[Flight_No]->Rank;
Replp1[Flight_No]->Seat_No=RP.Seat_No;
// cout<<"座"<<Replp1[Flight_No]->Seat_No;
p2=p2->Next;
}
Replp1[Flight_No]->Next=NULL;
}
p1=p1->Next;
Flight_No++;
}
Access.close();
}
//--------------从文件读取航班数据到链表函数-------------
void AccessFlightLine()
{
int size=sizeof(Flight);
fstream Access("Flight.txt",ios::binary|ios::in);
Access.seekp(0,ios::end);
long posEnd=Access.tellp();
Access.seekg(0,ios::beg);
long posBeg=Access.tellp();
Flight *p1;
while(Access.peek()!=EOF)
{
Access.read((char*)&FL,sizeof(Flight));
if(Head==NULL)
{
p1=p2=new Flight;
Head=p2;
}
else
{
p1=new Flight;
p2->Next=p1;
p2=p1; //保留当前航班结点地址
}
strcpy(p2->Des_Name,FL.Des_Name);
strcpy(p2->Flight_No,FL.Flight_No);
strcpy(p2->Plane_No,FL.Plane_No);
p2->Week_Day=FL.Week_Day;
p2->Customer_Amount=FL.Customer_Amount;
p2->Price[0]=FL.Price[0];
p2->Price[1]=FL.Price[1];
p2->Price[2]=FL.Price[2];
p2->CustNo=FL.CustNo;
p2->ReplNo=FL.ReplNo;
p2->Free_Amount=FL.Free_Amount;
p2->Customer_Amount=FL.Customer_Amount; //剩余票数与乘员定额相同
p2->CustName=NULL; //该航线定票乘客头指针为空
p2->ReplName=NULL; //初始候补名单为空
}
if(Access.peek()==EOF)
{
p2->Next=NULL; //航线的下一结点为空
Access.close();
// return;
}
}
//--------------航线查找函数-------------
//Find_Line()为重载函数//以航班号为参数进行查找
int Find_Line(Flight *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;
}
//引用调用,以航班号和整数Flight_No来记录该航班号所在航线,修改引用的指针为当前指针
int Find_Line(Flight *L,char *key,Flight *(&p2),int &Flight_No)
{
int flag=0; //该标志位0表示未找到相关信息,反之即找到
Flight *p1;
p1=L; //赋航线首结点
while(p1!=NULL)
{
if(strcmp(p1->Flight_No,key)==0)//不包括当前航线
{
flag=1;
p2=p1;
break;
}
p1=p1->Next; //指向下一航班结点
if(p1!=NULL) //遇结束符不作统计范围
Flight_No++;
}
return flag;
}
//-----------------航线添加函数-------------
void Line_Add()
{
Flight *p1; //建立临时航线结点
while(1)
{
if(Head==NULL)
{
p1=p2=new Flight;
Head=p2;
}
else
{
p1=new Flight;
p2->Next=p1; //前一航线结点指向当前航班结点
p2=p1; //保留当前航班结点地址
}
prefix("航线增设");
cout<<" 请输入终点站名:";
p2->CustNo=0;
p2->ReplNo=0;
cin>>p2->Des_Name;
while(1) //数据合法性检验
{
cout<<" 请输入航班号(唯一):";
cin>>p2->Flight_No;
if(Find_Line(Head,p2->Flight_No)) //存在航班号
cout<<" 输入的航班号不唯一!"<<endl;
else
break;
}
cout<<" 请输入飞机号:";
cin>>p2->Plane_No;
while(1)
{
cout<<" 请输入飞行周日(1-7):";
cin>>p2->Week_Day;
if(p2->Week_Day<1||p2->Week_Day>7)
{
cout<<" 数据输入错误,按任意键继续输入."<<endl;
getch();
}
else
break;
}
cout<<" 请输入乘员定额:";
cin>>p2->Customer_Amount;
cout<<" 请输入头等舱票价:";
cin>>p2->Price[0];
cout<<" 请输入普通舱票价:";
cin>>p2->Price[1];
cout<<" 请输入经济舱票价:";
cin>>p2->Price[2];
p2->Free_Amount=p2->Customer_Amount; //剩余票数与乘员定额相同
p2->CustName=NULL; //该航线定票乘客头指针为空
p2->ReplName=NULL; //初始候补名单为空
if(Continue()=='n')
{
p2->Next=NULL; //航线的下一结点为空
return;
}
}
}
//------------航线查看函数-----------------
void Line_See()
{
Flight *p1;
p1=Head;
char *Week_Day[]=...{"星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
if(Empty_Flight()) //航班线为空
return;
prefix("航班查看");
cout<<" ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ "<<endl;
cout<<" ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ 票 价 ┊"<<endl;
cout<<" ┊终点站┊航班号┊飞机号┊飞行周日┊乘员定额┊余票┊候补┊┈┈┈┈┈┈┈┈┊"<<endl;
cout<<" ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊头舱┊普舱┊经舱┊"<<endl;
cout<<" ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ "<<endl;
while(p1!=NULL)
{
cout<<" ┊"<<setiosflags(ios::left)<<setw(6)<<p1->Des_Name
<<"┊"<<setw(6)<<p1->Flight_No
<<"┊"<<setw(6)<<p1->Plane_No
<<"┊"<<setw(8)<<Week_Day[p1->Week_Day-1]
<<"┊ "<<setw(5)<<p1->Customer_Amount
<<"┊"<<setw(4)<<p1->Free_Amount
<<"┊"<<setw(4)<<p1->ReplNo
<<"┊"<<setw(4)<<p1->Price[0]
<<"┊"<<setw(4)<<p1->Price[1]
<<"┊"<<setw(4)<<p1->Price[2]
<<"┊"<<endl;
p1=p1->Next;
if(p1!=NULL)
cout<<" ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ "<<endl;
}
cout<<" ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ "<<endl;
cout<<" 按任意键返回上一级菜单..."<<endl;
getch();
}
//------------航线编辑函数-------------
void Line_Edit()
{
Line_See();
int Flight_No=0;
Flight *p1;
char search[6],answer;
cout<<" 请输入要修改的航线航班号:";
cin>>search;
if(Find_Line(Head,search,p1,Flight_No)) //返回航班所在航线的指针p1
{
cout<<" 请输入终点站名:";
cin>>p1->Des_Name;
cout<<" 是否修改航班号:";
cin>>answer;
if(answer=='y'||answer=='Y') //是否修改航班号
{
while(1) //数据合法性检验
{
cout<<" 请输入航班号(唯一):";
cin>>search;
if(Find_Line(Head,search)) //存在航班号
{
cout<<" 输入的航班号不唯一!"<<endl;
}
else
{
strcpy(p1->Flight_No,search);
break;
}
}
}
cout<<" 请输入飞机号:";
cin>>p1->Plane_No;
while(1)
{
cout<<" 请输入飞行周日(1-7):";
cin>>p1->Week_Day;
if(p1->Week_Day<1||p1->Week_Day>7)
{
cout<<" 数据输入错误,按任意键继续输入."<<endl;
getch();
}
else
break;
}
cout<<" 请输入乘员定额:";
cin>>p1->Customer_Amount;
cout<<" 请输入头等舱票价:";
cin>>p1->Price[0];
cout<<" 请输入普通舱票价:";
cin>>p1->Price[1];
cout<<" 请输入经济舱票价:";
cin>>p1->Price[2];
cout<<" 请注意已订票乘客和候补不能修改";
p1->Free_Amount=p1->Customer_Amount-p1->CustNo; //剩余票数与乘员定额相同
cout<<" 修改后的剩余票数:"<<p1->Free_Amount<<endl;
}
else cout<<" 找不到相关航线!";
cout<<" 按任意键重新显示航班..."<<endl;
getch();
Line_See();
}
//--------------航线查找函数-------------
void Line_Find() //根据终点站来查询所有的相关航线
{
system("cls");
char Line_Name[10];
int find=1;
prefix("航班查找");
cout<<" 请输入要查找的航线终点站名:";
cin>>Line_Name;
Flight *p1;
p1=Head;
char *Week_Day[]={"星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
if(Empty_Flight()) //航班线为空
return;
cout<<" ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ "<<endl;
cout<<" ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ 票 价 ┊"<<endl;
cout<<" ┊终点站┊航班号┊飞机号┊飞行周日┊乘员定额┊剩余┊候补┊┈┈┈┈┈┈┈┈┊"<<endl;
cout<<" ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊头舱┊普舱┊经舱┊"<<endl;
cout<<" ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ "<<endl;
while (p1!=NULL)
{
if (strcmp(Line_Name,p1->Des_Name)==0)
{
find=0;
cout<<" ┊"<<setiosflags(ios::left)<<setw(6)<<p1->Des_Name
<<"┊"<<setw(6)<<p1->Flight_No
<<"┊"<<setw(6)<<p1->Plane_No
<<"┊"<<setw(8)<<Week_Day[p1->Week_Day-1]
<<"┊ "<<setw(5)<<p1->Customer_Amount
<<"┊"<<setw(4)<<p1->Free_Amount
<<"┊"<<setw(4)<<p1->ReplNo
<<"┊"<<setw(4)<<p1->Price[0]
<<"┊"<<setw(4)<<p1->Price[1]
<<"┊"<<setw(4)<<p1->Price[2]
<<"┊"<<endl;
cout<<" ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ "<<endl;
}
p1=p1->Next;
}
if(find)
cout<<" ┈┈┈┈┈┈┈┈┈┈┈┈┈没有找到相关航线┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ "<<endl;
cout<<" 按任意键返回上一级菜单..."<<endl;
getch();
}
//--------------推荐航线查找函数-------------
void OtherLine(int Ticket_Count,char *Line_Name)
{
cout<<" 当前操作:"<<"系统推荐同终点站航线"<<endl;
cout<<" ";
cout<<"┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈";
cout<<endl;
int flag=1;
Flight *p1;
p1=Head;
char *Week_Day[]=...{"星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
if(Empty_Flight()) //航班线为空
return;
cout<<" ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ "<<endl;
cout<<" ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ 票 价 ┊"<<endl;
cout<<" ┊终点站┊航班号┊飞机号┊飞行周日┊乘员定额┊剩余┊候补┊┈┈┈┈┈┈┈┈┊"<<endl;
cout<<" ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊头舱┊普舱┊经舱┊"<<endl;
cout<<" ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ "<<endl;
while (p1!=NULL)
{
if (strcmp(Line_Name,p1->Des_Name)==0&&Ticket_Count<=p1->Free_Amount)
{
cout<<" ┊"<<setiosflags(ios::left)<<setw(6)<<p1->Des_Name
<<"┊"<<setw(6)<<p1->Flight_No
<<"┊"<<setw(6)<<p1->Plane_No
<<"┊"<<setw(8)<<Week_Day[p1->Week_Day-1]
<<"┊ "<<setw(5)<<p1->Customer_Amount
<<"┊"<<setw(4)<<p1->Free_Amount
<<"┊"<<setw(4)<<p1->ReplNo
<<"┊"<<setw(4)<<p1->Price[0]
<<"┊"<<setw(4)<<p1->Price[1]
<<"┊"<<setw(4)<<p1->Price[2]
<<"┊"<<endl;
cout<<" ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ "<<endl;
flag=0;
}
p1=p1->Next;
}
if(flag)
cout<<" ┈┈┈┈┈┈┈┈┈┈┈┈没有找到同终点站的航线┈┈┈┈┈┈┈┈┈┈┈┈┈┈ "<<endl;
cout<<" 按任意键返回订票程序..."<<endl;
getch();
}
void LineMenu()
{
char *MenuItem[]=
{
"┊ 航空客运航线管理子菜单 ┊",
" ┊[1]. 航 线 增 设 ┊ ",
" ┊[2]. 航 线 查 看 ┊ ",
" ┊[3]. 航 线 查 找 ┊ ",
" ┊[4]. 航 线 修 改 ┊ ",
" ┊[5]. 返 回 主 菜 单 ┊ "
};
while(1)
switch(ModelMenu(MenuItem,6))
{
case '1':{Line_Add();break;}
case '2':{Line_See();break;}
case '3':{Line_Find();break;}
case '4':{Line_Edit();break;}
case '5':{return;}
default:{ErrorMess();}
}
}
//---------------订票办理函数---------------
void ReseMenu()
...{
Line_See();
int Ticket_Count,Seat_No,flag=0;
int Flight_No=0; //记录满足条件的航线的定票结点
Flight *p1; //记下满足条件的航线结点地址
Customer *p2; //临时性定票乘员结点
Replace *p3; //临时性候补乘员结点
char answer[7]; //用户输入的航班数据
char temp;
int tag=0; //候补乘客标志位
int Amount;
int IsRepl=0; //是否执行候补操作标志位
if(Empty_Flight()) //航班线为空
return;
while(1)
{
cout<<" 当前操作:"<<"订票办理"<<endl;
cout<<" ";
cout<<"┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈"<<endl;
flag=0; //标志位清零以重新作出判断
Flight_No=0;
tag=0;
cout<<" 请输入航班号:";
cin>>answer;
if(Find_Line(Head,answer,p1,Flight_No)) //调用航线查找函数,若存在则进行以下操作
{
while(1) //数据合法性检验
{
cout<<" 请输入定票数:";
cin>>Ticket_Count;
if(Ticket_Count==0)
{
cout<<" 请输入大于零的数,按任意键继续输入."<<endl;
getch();
}
else
break;
}
if(p1->Free_Amount>=Ticket_Count)
{
Customer_Count++; //定票乘客总数增1
flag=1; //表明进入了订票实际操作
IsRepl=1; //定票量满足,无需进入候补操作
Amount=p1->Free_Amount; //记录剩余票数
if(p1->CustName==NULL) //首个定票乘客,并记录相关属性
{
Custp1[Flight_No]=p2=new Customer; //建立该航线的首位乘客结点
p1->CustName=Custp1[Flight_No];
}
else //建立该航线的后续乘客结点
{
p2=new Customer;
Custp1[Flight_No]->Next=p2;
Custp1[Flight_No]=p2;
}
IsEmpty=0; //定票乘员不为空
Custp1[Flight_No]->Amount=Ticket_Count; //订票数
Seat_No=p1->Customer_Amount-p1->Free_Amount+1; //算出座位号
Custp1[Flight_No]->Seat_No=Seat_No; //赋座位号
p1->Free_Amount-=Ticket_Count; //减去定票数
p1->CustNo=p1->CustNo+Ticket_Count; //单航线总乘客数
cout<<" 该航线总订票数:"<<p1->CustNo<<endl;
cout<<" 请输入你的姓名:";
cin>>Custp1[Flight_No]->Name;
while(1) //数据合法性检验
{
cout<<" 请输入舱位等级(1-3):";
cin>>Custp1[Flight_No]->Rank;
if(!(Custp1[Flight_No]->Rank>=1&&Custp1[Flight_No]->Rank<=3))
{
cout<<" 输入出错,请输入1-3之间的数,按任意键继续输入."<<endl;
getch();
}
else
break;
}
cout<<" 您的座位号为:";
if(Ticket_Count>1) //为显示规整,作相应处理打印座位号
{
cout<<Seat_No<<"-";
Seat_No=Seat_No+Ticket_Count-1;
cout<<Seat_No<<endl;
}
else cout<<Seat_No<<endl;
}//满足定票数
else if(p1->Free_Amount==0)
{
cout<<" 对不起,该航线的票已经全部售完!"<<endl;
IsRepl=0;
}
else
{
cout<<" 对不起,该航线的剩余票额数少于你的订票数。"<<endl;
IsRepl=0;
}
if(!IsRepl)
{
OtherLine(Ticket_Count,p1->Des_Name);
cout<<" 是否列入"<<p1->Des_Name<<p1->Flight_No<<"航线候补乘客名单(Y/N)?";
cin>>temp;
if(temp=='y'||temp=='Y')//以下为候补操作
{
if(p1->ReplName==NULL)
{
Replp1[Flight_No]=p3=new Replace; //建立该航线的首位候补乘客结点
p1->ReplName=Replp1[Flight_No];
Replp1[Flight_No]->Seat_No=Seat_No+1; //第一个候补的第一个座位号
}
else
{
p3=new Replace;
Replp1[Flight_No]->Next=p3;
Replp1[Flight_No]=p3;
Replp1[Flight_No]->Seat_No=p1->Customer_Amount+p1->ReplNo+1; //候补乘客的第一个座位号
}
IsReplace=0; //候补乘客不为空
tag=1; //已选择列入候补乘客名单
cout<<" 请输入你的姓名:";
cin>>Replp1[Flight_No]->Name;
Replp1[Flight_No]->Amount=Ticket_Count; //候补乘客的订票数
Seat_No=Replp1[Flight_No]->Seat_No-1;
p1->ReplNo=p1->ReplNo+Ticket_Count;
cout<<" 当前候补数:"<<p1->ReplNo<<endl;
while(1) //数据合法性检验
{
cout<<" 请输入舱位等级(1-3):";
cin>>Replp1[Flight_No]->Rank;
if(!(Replp1[Flight_No]->Rank>=1&&Replp1[Flight_No]->Rank<=3))
{
cout<<" 输入出错,请输入1-3之间的数,按任意键继续输入."<<endl;
getch();
}
else
break;
}
cout<<" 虚拟座位:"<<Replp1[Flight_No]->Seat_No<<"-"<<Replp1[Flight_No]->Seat_No+Ticket_Count-1<<endl;//候补乘客无座提示
}//进入候补名单
}//票数满足
}//航线存在
else
cout<<" 对不起,没有该次航班,按任意继续操作."<<endl;//航线不存在
if(flag) //此处不作处理,则会地址溢出
Custp1[Flight_No]->Next=NULL;//末位定票乘客的指针置空
if(tag)
{
Replp1[Flight_No]->Next=NULL;//末位候补乘客的指针置空
cout<<" 该乘客已成功列入该航线的候补名单."<<endl;
}
if(Continue()=='n')
return;
}//while
}