/* 航空客运订票系统
问题描述
航空客运订票的业务活动包括:查询航线、客票预订和办理退票等。设计一个航空客运订票系统,以使上述业
务可以借助计算机完成。
要求
每条航线所涉及的信息有:终点站名、航班号、飞机号、飞行周日(星期几)、乘员定额、余票量、已订票的
客户名单(包括名字、订票量、舱位等级1、2、3)以及等候替补的客户名单;
系统实现的功能如下:
通过此系统可以实现如下功能:
录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)
查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确
定航班是否满仓);可以输入起飞抵达城市,查询飞机航班情况;
订票:(订票情况可以存在一个数据文件中,结构自己设定)可以订票,如果该航班已经无票,可以提供相关
可选择航班;
退票: 可退票,退票后修改相关数据文件;客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。
修改航班信息:当航班信息改变可以修改航班数据文件
*/
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<fstream.h>
#include<windows.h>
class daytime
{
public:
int weekday;
int hour;
int minute;
daytime()
{
weekday=hour=minute=0;
}
~daytime()
{}
};
class samepart
{
public:
char begcity[20]; // 起点城市
char arrivecity[20]; // 终点城市
char hangbancode[10]; // 航班编号
int flycode; // 飞机号
daytime lefttime; // 起飞时间
daytime arrivetime; // 到达时间
samepart()
{
strcpy(begcity,"");
strcpy(arrivecity,"");
strcpy(hangbancode,"");
strcpy(hangbancode,"");
flycode=0;
}
~samepart()
{}
};
class seat
{
public:
int chars;
double price;
int leftseat;
int position; // 座位号
seat()
{
chars=leftseat=position=0;
price=0;
}
~seat()
{}
};
class guestmessage:public samepart
{
public:
int sum;
long ID; // 证件号
int linedata; // 订票编号
char name[20];
int total; // 订票总数
int dengji;
int seats[10];
guestmessage *next;
guestmessage()
{
for(int i=0;i<10;i++)
seats[i]=0;
ID=linedata=0;
strcpy(name,"");
};
~guestmessage()
{
};
};
class blackseat
{
public:
int counter;
char hangbancode[10];
int flycode;
int chars;
int position;
blackseat *next;
blackseat()
{
strcpy(hangbancode,"");
flycode=0;
chars=0;
position=0;
counter=0;
}
};
struct operater // 机场工作人员姓名与工作密码
{
char code[20];
char name[20];
};
class flymessage:public samepart
{
public:
int counter;
int maxseat; // 最大容量
double count; // 打折数
seat seats[4];
bool empty; // 是否满舱
int didbook; // 已经订票人数
flymessage *next;
flymessage()
{
maxseat=didbook=0;
empty=false;
count=0.0;
};
~flymessage()
{};
};
istream & operator>>(istream &in,flymessage &flymess) //重载运算符>>
{
in>>flymess.hangbancode;
in>>flymess.flycode;
in>>flymess.begcity;
in>>flymess.arrivecity;
in>>flymess.count;
in>>flymess.didbook;
in>>flymess.maxseat;
in>>flymess.lefttime.weekday;
in>>flymess.lefttime.hour;
in>>flymess.lefttime.minute;
in>>flymess.arrivetime.weekday;
in>>flymess.arrivetime.hour;
in>>flymess.arrivetime.minute;
for(int i=1;i<4;i++)
{
in>>flymess.seats[i].leftseat;
in>>flymess.seats[i].price;
}
return in;
}
ostream & operator <<(ostream &os,flymessage &flymess) //重载运算符<<
{
os<<flymess.hangbancode<<'\t';
os<<flymess.flycode<<'\t';
os<<flymess.begcity<<'\t';
os<<flymess.arrivecity<<'\t';
os<<flymess.count<<'\t';
os<<flymess.didbook<<'\t';
os<<flymess.maxseat<<'\t';
os<<flymess.lefttime.weekday<<" ";
os<<flymess.lefttime.hour<<" ";
os<<flymess.lefttime.minute<<" ";
os<<flymess.arrivetime.weekday<<" ";
os<<flymess.arrivetime.hour<<" ";
os<<flymess.arrivetime.minute<<'\t';
for(int i=1;i<4;i++)
{
os<<flymess.seats[i].leftseat<<" ";
os<<flymess.seats[i].price<<'\t';
}
os<<endl;
return os;
}
istream & operator >>(istream &in,guestmessage &guest) //重载运算符>>
{
in>>guest.hangbancode;
in>>guest.flycode;
in>>guest.begcity;
in>>guest.arrivecity;
in>>guest.lefttime.weekday;
in>>guest.lefttime.hour;
in>>guest.lefttime.minute;
in>>guest.arrivetime.weekday;
in>>guest.arrivetime.hour;
in>>guest.arrivetime.minute;
in>>guest.ID;
in>>guest.name;
in>>guest.linedata;
in>>guest.total;
in>>guest.dengji;
return in;
}
ostream & operator<<(ostream &os,guestmessage &guest) //重载运算符<<
{
os<<guest.hangbancode<<'\t';
os<<guest.flycode<<'\t';
os<<guest.begcity<<'\t';
os<<guest.arrivecity<<'\t';
os<<guest.lefttime.weekday<<" ";
os<<guest.lefttime.hour<<" ";
os<<guest.lefttime.minute<<'\t';
os<<guest.arrivetime.weekday<<" ";
os<<guest.arrivetime.hour<<" ";
os<<guest.arrivetime.minute<<'\t';
os<<guest.ID<<'\t';
os<<guest.name<<'\t';
os<<guest.linedata<<'\t';
os<<guest.total<<'\t';
os<<guest.dengji;
os<<endl;
return os;
}
istream & operator << (istream &in,blackseat &blackst)
{
in>>blackst.chars;
in>>blackst.hangbancode;
in>>blackst.flycode;
in>>blackst.position;
return in;
}
ostream & operator>>(ostream &os,blackseat &blackst)
{
os<<blackst.chars<<'\t';
os<<blackst.hangbancode<<'\t';
os<<blackst.flycode<<'\t';
os<<blackst.position<<endl;
return os;
}
//------------------------------------------------------------------------------------------
void inifiledata() // 初始化航班信息文件、查询索引表文件的数据
{
fstream datafile1,datafile2,datafile3,datafile4;
datafile1.open("航班的基本信息数据.dat",ios::out);
if(!datafile1)
cout<<"航班的基本信息数据.dat文件不存在!"<<endl;
else
datafile1<<0<<endl;
datafile1.close();
datafile2.open("客户信息库.dat",ios::out);
if(!datafile2)
cout<<"客户信息库.dat文件不存在!"<<endl;
else
datafile2<<0<<endl;
datafile2.close();
datafile3.open("已订票的客户座位信息.dat",ios::out);
if(!datafile3)
cout<<"已订票的客户座位信息文件不存在!"<<endl;
datafile3<<0<<endl;
datafile3.close();
datafile4.open("退票的位子信息.txt",ios::out);
if(!datafile4)
cout<<"退票后的空位文件不存在"<<endl;
else
datafile4<<0<<endl;
datafile4.close();
system("cls");
cout<<"所有数据文件已经初始化!"<<endl;
}
//-----------------------------------------------------------------------------------------
void savealldata(flymessage *hangban) //将工作人员所修改的数据保存
{
fstream hangbanfile;
flymessage *p;
p=hangban->next;
hangbanfile.open("航班的基本信息数据.dat",ios::out);
hangbanfile<<hangban->counter<<endl;
if(hangban->counter==1)
hangbanfile<<*hangban;
else
{
while(p!=NULL)
{
hangbanfile<<*p;
p=p->next;
}
}
hangbanfile.flush();
hangbanfile.close();
cout<<"以上信息数据已保存到磁盘中!"<<endl;
}
flymessage *readalldata() // 从文件中读取航班信息数据
{
fstream hangbanfile;
flymessage *p,*head,*q;
q=head=new flymessage;
head->next=NULL;
hangbanfile.open("航班的基本信息数据.dat",ios::in);
hangbanfile>>head->counter;
if(head->counter==0)
{
cout<<"文件中没有任何数据"<<endl;
return head;
}
for(int i=0;i<head->counter;i++)
{
p=new flymessage;
p->next=NULL;
q->next=p;
q=p;
hangbanfile>>*p;
}
hangbanfile.flush();
hangbanfile.close();
return head;
}
//---------------------------------------------------------------------------------------
bool writemessage() // 录入信息,建立数据文件
{
flymessage *hangban,*p,*q,*s;
double ct;
char ach[20],bch[20],ch,hbd[10];
int fcd,mst;
seat st[4];
daytime lefttime,arrivetime;
cout<<"请输入航班起点城市名:";
cin>>bch;
cout<<"请输入航班到达城市名:";
cin>>ach;
cout<<"请输入航班号:";
cin>>hbd;
cout<<"请输入飞机号:";
cin>>fcd;
cout<<"请输入改航班的最大容量:";
cin>>mst;
cout<<"请输入该飞机"<<bch<<"起飞时间:星期 小时 分钟";
cin>>lefttime.weekday>>lefttime.hour>>lefttime.minute;
cout<<"请输入该飞机到达"<<ach<<"的时间:星期 小时 分钟";
cin>>arrivetime.weekday>>arrivetime.hour>>arrivetime.minute;
for(int i=1;i<4;i++)
{
st[i].chars=i;
cout<<"请输入"<<i<<"等舱的价格票价:";
cin>>st[i].price;
cout<<"请输入"<<i<<"等舱的剩余量:";
cin>>st[i].leftseat;
}
cout<<"请输入航线的打折情况:";
cin>>ct;
hangban=new flymessage;
hangban->didbook=0;
strcpy(hangban->begcity,bch);
strcpy(hangban->arrivecity,ach);
hangban->flycode=fcd;
strcpy(hangban->hangbancode,hbd);
hangban->maxseat=mst;
hangban->lefttime.weekday=lefttime.weekday;
hangban->lefttime.hour=lefttime.hour;
hangban->lefttime.minute=lefttime.minute;
hangban->arrivetime.weekday=arrivetime.weekday;
hangban->arrivetime.hour=arrivetime.hour;
hangban->arrivetime.minute=arrivetime.minute;
hangban->count=ct;
for( i=1;i<4;i++)
{
hangban->seats[i].chars=i;
hangban->seats[i].price=st[i].price;
hangban->seats[i].leftseat=st[i].leftseat;
}
hangban->empty=true;
s=p=new flymessage;
p=readalldata();
q=p->next;
if(p->next==NULL)
{
hangban->counter=1;
savealldata(hangban);
}
else
{
while(q!=NULL)
{
s->next=q;
s=q;
q=q->next;
}
s->next=hangban;
hangban->next=NULL;
p->counter++;
savealldata(p);
}
cout<<"是否继续录入y/n?"<<endl;
cin>>ch;
while(1)
{
if((ch=='y')||(ch=='Y'))
return true;
else if((ch=='n')||(ch=='N'))
return NULL;
else
{
cout<<"输入错误,请重新输入";
cin>>ch;
}
}
}