//此航班订票系统由我一同学方辉制作。本人并不喜欢此设计。原因..。
//此设计基本实现了系统所要求的各项基本功能。
//不及细看。有不足之处,请帮他指正。/July.整理。06.02/。
#include<iostream.h>
#include<string.h>
#include<fstream.h>
#include <iomanip.h>
class
Plan
//航班类
{
char
num[20];
//航班号
char
s[20];
//出发站
char
e[20];
//到达站
char
t[20];
//起飞时间
int
fee;
//票价
int
sum;
//总票数
int
n;
//剩余票数
Plan
*next;
//下个航班
public:
Plan(){}
~Plan(){}
char *getnu(){return num;}
void setnu(char *n){strcpy(num,n);}
char *gets(){return s;}
void sets(char
*s){strcpy(this->s,s);}
char *gete(){return e;}
void sete(char
*e){strcpy(this->e,e);}
char *gett(){return t;}
void sett(char
*t){strcpy(this->t,t);}
int getf(){return fee;}
void
setf(int f){fee=f;}
int getsu(){return sum;}
void
setsu(int s){sum=s;}
int
getn(){return n;}
void
setn(int n){this->n=n;}
Plan *getnext(){return next;}
void setnext(Plan*n){next=n;}
};
class
Client
//乘客类
{
char
num[20];
//航班号
char
name[20];
//乘客姓名
int
n;
//所购票数
Client *next;
public:
Client(){}
~Client(){}
char *getna(){return name;}
void setna(char *n){strcpy(name,n);}
char *getnu(){return num;}
void setnu(char *n){strcpy(num,n);}
int
getn(){return n;}
void
setn(int n){this->n=n;}
Client *getnext(){return next;}
void setnext(Client*n){next=n;}
};
class
manage
//管理类
{
private:
Plan
*head1;
//航班头指针
Plan
*last1;
Client
*head2;
//乘客头指针
Client *last2;
public:
manage(){}
~manage(){}
void ini();
void
newf();
void
buy();
void
show1();
void
show2();
void
modify();
void
del();
void
delall();
void
baClient();
void
query1();
void
query2();
void
save();
void
run();
};
void
manage::ini()
//读取文件
{
head1=last1=NULL; head2=last2=NULL;
ifstream
rf("plane.txt",ios::out|ios::nocreate,filebuf::openprot);
if(rf.fail())cout<<"\n提示,文件读取失败!\n";
else
{
int
n=0;
//得到个数
rf.read((char
*)&n,sizeof(n));
//得到航班个数
for(int
i=0;i<n;i++)
{
Plan *p1=new
Plan;
rf.read((char*)p1,sizeof(Plan));
p1->setnext(NULL);
if(head1==NULL)head1=last1=p1;
else
{last1->setnext(p1);last1=p1;}
}
cout<<"\n初始化"<<i<<"条航班信息成功!";
rf.read((char
*)&n,sizeof(n));
//得到乘客个数
for(
i=0;i<n;i++)
{
Client
*p2=new Client;
rf.read((char*)p2,sizeof(Client));
p2->setnext(NULL);
if(head2==NULL)head2=last2=p2;
else
{last2->setnext(p2);last2=p2;}
}
cout<<"\n初始化"<<i<<"条乘客信息成功!";
}
rf.close();
}
void
manage::newf()
//录入航班信息
{
Plan*p;
p=new Plan;
cout<<"\n录入航班信息\n";
char c[50];
cout<<"请输入航班号\n";
cin>>c;
p->setnu(c);
cout<<"请输入起始地\n";
cin>>c;
p->sets(c);
cout<<"请输入目的地\n";
cin>>c;
p->sete(c);
cout<<"请输入起飞日期(年/月/日/时:分)\n";
cin>>c;
p->sett(c);
cout<<"\n请输入机票金额\n\n";
int n;
cin>>n;p->setf(n);
cout<<"\n请输入机票总数\n\n";
cin>>n;p->setsu(n);
p->setn(n);
p->setnext(NULL);
if(head1){last1->setnext(p);last1=p;}
else
head1=last1=p;
cout<<"\n新航班创建成功\n\n";
}
void manage::buy()
{
if(head1==NULL){cout<<"提示:无航班信息!\n";return
;}
cout<<"\n\n\n\n
购买机票\n";
char c[50];
cout<<"\n请输入航班号\n";
cin>>c;
int y=1;
Plan *p=head1;
while(p)
{
if(strcmp(p->getnu(),c)==0)
{y=0;break;}
p=p->getnext();
}
if(y){cout<<"\n错误,无此航班号!";return;}
if(p->getn()<=0){cout<<"\n提示,此航班票已经售完!\n";return;}
cout<<"\n|---------------------------------------------------------------------------|";
cout<<"\n 航次:
"<<p->getnu()<<"
起飞时间:"<<p->gett()<<"
总票数:
"<<p->getsu();
cout<<"\n
航线:"<<p->gets()<<"--->
"<<p->gete()<<"
票价:"<<p->getf()<<"
剩余票数:
"<<p->getn();
cout<<"\n|---------------------------------------------------------------------------|\n";
Client *p1;
p1=new Client;
p1->setnext(NULL);
p1->setnu(c);
cout<<"\n-------------------------请进行购票登记
---------------------------";
cout<<"\n请输入姓名:\n";
cin>>c;
p1->setna(c);
loop:
cout<<"\n请输入购买票数:\n";
int n;
cin>>n;
if(n>p->getn())
{
cout<<"\n提示,您最多只能购买"<<p->getn()<<"张票!";
goto loop;
}
p1->setn(n);
p->setn(p->getn()-n);
if(head2==NULL)head2=last2=p1;
else {last2->setnext(p1);
last2=p1;}
cout<<"\n------------买票成功,您需要付款:"<<p->getf()*p1->getn()<<"元-----------------";
}
void manage::show1()
{
if(head1==NULL){cout<<"航班信息为空!\n\n";return;}
Plan *p=head1;
cout<<setw(50)<<"航班信息";
while(p)
{
cout<<"\n
航次:
"<<p->getnu()<<"
起飞时间:"<<p->gett()<<"
总票数:
"<<p->getsu();
cout<<"\n
航线:"<<p->gets()<<"--->
"<<p->gete()<<"
票价:"<<p->getf()<<"
剩余票数:
"<<p->getn();
cout<<"\n|---------------------------------------------------------------------------|\n";
p=p->getnext();
}
}
void manage::show2()
{
if(head2==NULL){cout<<"乘客信息为空!\n\n";return;}
Client *p=head2;
cout<<setw(50)<<"
乘客信息";
while(p)
{
cout<<"\n
姓名 :
"<<p->getna()<<"
航班号:"<<p->getnu()<<"
所购票数:
"<<p->getn();
cout<<"\n|---------------------------------------------------------------------------|\n";
p=p->getnext();
}
}
void manage::modify()
{
cout<<setw(50)<<"修改航班";
Plan *p=head1;
char m[20];
int y=1;
cout<<"\n\n请输入要修改的航班\n\n";
cin>>m;
while(p)
{
if(strcmp(p->getnu(),m)==0)
{
y=0;
cout<<"\n请修改起始地\n\n";
cin>>m;
p->sets(m);
cout<<"\n请修改目的地\n\n";
cin>>m;
p->sete(m);
cout<<"\n请修改登机时间(年/月/日/时:分)\n\n";
cin>>m;p->sett(m);
cout<<"\n请修改机票价格\n\n";
int n;
cin>>n;
p->setf(n);
loop:
cout<<"\n请修改机票总数\n";
cin>>n;
if(n<p->getsu()-p->getn()){cout<<"\n错误,机票总数必须>=已售机票数!\n";goto
loop;}
p->setn(
n-(p->getsu()-p->getn()) );
p->setsu(n);
}
p=p->getnext();
}
if(y)
cout<<"\n错误,无此航班号!";
else
cout<<"\n航班修改成功!";
}
void manage::del()
{
if(head1==NULL){cout<<"\n\n提示:无航班信息!";return
;}
cout<<setw(50)<<"
删除航班";
Plan *temp,*p=head1;
char m[20];
int y=1;
loop:
cout<<"\n\n请输入要删除的航班\n\n";
cin>>m;
if(strcmp(head1->getnu(),m)==0)
{
if(head1->getsu()!=head1->getn())
{
cout<<"\n该航班已经开始售票,不能取消!\n\n";goto
loop;}
y=0;
temp=head1;
head1=head1->getnext();
}
else
while(p->getnext())
{
if(strcmp(p->getnext()->getnu(),m)==0)
{
if(p->getnext()->getsu()!=p->getnext()->getn())
{
cout<<"\n该航班已经开始售票,不能取消!\n\n";goto
loop;}
y=0;
temp=p->getnext();
p->setnext(temp->getnext());
break;
}
p=p->getnext();
}
if(y)
cout<<"\n错误,无此航班号!";
else
{ delete temp;
cout<<"\n\n操作成功!";}
}
void manage::delall()
{
cout<<setw(50)<<"
清空信息";
Plan *p1=head1;
while(p1)
{
Plan
*temp1=p1->getnext();
delete p1;
p1=temp1;
}
head1=last1=NULL;
Client *p2=head2;
while(p2)
{
Client *
temp2=p2->getnext();
delete p2;
p2=temp2;
}
head2=last2=NULL;
cout<<"\n\n信息清空成功!";
}
void manage::query1() //查找航班信息
{
char c;
char m[30];
manage* q=new manage;
if(head1==NULL){cout<<"\n\n提示:无航班信息!";return
;}
do
{
cout<<setw(50)<<"
│
[航班查询菜单]
│\n";
cout<<setw(50)<<"
│ 按起始地查询
1,并按回车键
│\n";
cout<<setw(50)<<"
│ 按目的地查询
2,并按回车键
│\n";
cout<<setw(50)<<"
│
返回 3,并按回车键
│\n";
Plan *p=head1;
cin>>c;
switch (c)
{
case '1':
{
int
y=1;
cout<<"\n\n请输入要查找的起始地\n\n";
cin>>m;
while(p)
{
if(strcmp(p->gets(),m)==0)
{
cout<<"\n|-----------------------------------------------------------------------------|";
cout<<"\n
航次:
"<<p->getnu()<<"
起飞时间:"<<p->gett()<<"
总票数:
"<<p->getsu();
cout<<"\n
航线:"<<p->gets()<<"--->
"<<p->gete()<<"
票价:"<<p->getf()<<"
剩余票数:
"<<p->getn();
cout<<"\n|---------------------------------------------------------------------------|\n";
y=0;
}
p=p->getnext();
}
if(y)cout<<"失败,您查询的航班不存在!\n\n";
}
break;
case'2':
{
int
y=1;
cout<<"\n\n请输入要查找的目的地\n\n";
cin>>m;
while(p)
{
if(strcmp(p->gete(),m)==0)
{
cout<<"\n
航次:
"<<p->getnu()<<"
起飞时间:"<<p->gett()<<"
总票数:
"<<p->getsu();