c++设计航班订票系统 航空订票系统详细设计

//此航班订票系统由我一同学方辉制作。本人并不喜欢此设计。原因..。

//此设计基本实现了系统所要求的各项基本功能。

//不及细看。有不足之处,请帮他指正。/July.整理。06.02/。

#include<iostream.h>
#include<string.h>
#include<fstream.h>
#include <iomanip.h>


classPlan//航班类
{

charnum[20];//航班号
chars[20];//出发站
chare[20];//到达站
chart[20];//起飞时间
intfee;//票价
intsum;//总票数
intn;//剩余票数
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;}
c++设计航班订票系统 航空订票系统详细设计
void sett(char*t){strcpy(this->t,t);}
int getf(){return fee;}
voidsetf(int f){fee=f;}
int getsu(){return sum;}
voidsetsu(int s){sum=s;}
intgetn(){return n;}
voidsetn(int n){this->n=n;}
Plan *getnext(){return next;}
void setnext(Plan*n){next=n;}
};


classClient//乘客类
{
charnum[20];//航班号
charname[20];//乘客姓名
intn;//所购票数
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);}
intgetn(){return n;}
voidsetn(int n){this->n=n;}
Client *getnext(){return next;}
void setnext(Client*n){next=n;}
};


classmanage//管理类
{
private:
Plan*head1;//航班头指针
Plan*last1;
Client*head2;//乘客头指针
Client *last2;
public:
manage(){}
~manage(){}
void ini();
voidnewf();
voidbuy();
voidshow1();
voidshow2();
voidmodify();
voiddel();
voiddelall();
voidbaClient();
voidquery1();
voidquery2();
voidsave();
voidrun();
};


voidmanage::ini()//读取文件
{
head1=last1=NULL; head2=last2=NULL;
ifstreamrf("plane.txt",ios::out|ios::nocreate,filebuf::openprot);
if(rf.fail())cout<<"n提示,文件读取失败!n";
else
{
intn=0;//得到个数
rf.read((char*)&n,sizeof(n));//得到航班个数
for(inti=0;i<n;i++)
{
Plan *p1=newPlan;
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();
}


voidmanage::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请输入机票金额nn";
int n;
cin>>n;p->setf(n);
cout<<"n请输入机票总数nn";
cin>>n;p->setsu(n);
p->setn(n);
p->setnext(NULL);
if(head1){last1->setnext(p);last1=p;}
else
head1=last1=p;
cout<<"n新航班创建成功nn";
}


void manage::buy()
{
if(head1==NULL){cout<<"提示:无航班信息!n";return;}
cout<<"nnnn购买机票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<<"航班信息为空!nn";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<<"乘客信息为空!nn";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<<"nn请输入要修改的航班nn";
cin>>m;
while(p)
{
if(strcmp(p->getnu(),m)==0)
{
y=0;
cout<<"n请修改起始地nn";
cin>>m;
p->sets(m);
cout<<"n请修改目的地nn";
cin>>m;
p->sete(m);
cout<<"n请修改登机时间(年/月/日/时:分)nn";
cin>>m;p->sett(m);
cout<<"n请修改机票价格nn";
int n;
cin>>n;
p->setf(n);
loop:
cout<<"n请修改机票总数n";
cin>>n;
if(n<p->getsu()-p->getn()){cout<<"n错误,机票总数必须>=已售机票数!n";gotoloop;}
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<<"nn提示:无航班信息!";return;}
cout<<setw(50)<<"删除航班";
Plan *temp,*p=head1;
char m[20];
int y=1;
loop:
cout<<"nn请输入要删除的航班nn";
cin>>m;
if(strcmp(head1->getnu(),m)==0)
{
if(head1->getsu()!=head1->getn())
{cout<<"n该航班已经开始售票,不能取消!nn";gotoloop;}
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该航班已经开始售票,不能取消!nn";gotoloop;}
y=0;
temp=p->getnext();
p->setnext(temp->getnext());
break;
}
p=p->getnext();
}
if(y)
cout<<"n错误,无此航班号!";
else
{ delete temp;cout<<"nn操作成功!";}
}


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<<"nn信息清空成功!";
}


void manage::query1() //查找航班信息
{
char c;
char m[30];
manage* q=new manage;
if(head1==NULL){cout<<"nn提示:无航班信息!";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':
{
inty=1;
cout<<"nn请输入要查找的起始地nn";
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<<"失败,您查询的航班不存在!nn";
}
break;
case'2':
{
inty=1;
cout<<"nn请输入要查找的目的地nn";
cin>>m;
while(p)
{
if(strcmp(p->gete(),m)==0)
{
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<<"失败,您查询的航班不存在!nn";
}
break;
case'3':
q->manage::run();
break;
}
}
while(c!='c'&&c!='C');
}


void manage::query2() //查找乘客信息
{
if(head1==NULL){cout<<"nn提示:无航班信息!";return;}
char c,m[20];
do
{
cout<<setw(50)<<"│[乘客查询菜单]│n";
cout<<setw(50)<<"│ 乘客查询菜单1,并按回车键│n";
cout<<setw(50)<<"│ 乘客查询菜单2,并按回车键│n";
cout<<setw(50)<<"│返回 3,并按回车键│n";
cin>>c;
switch (c)
{
case '1':
{
Plan*p1=head1;
Client*p2=head2;
inty1=1,y2=1;
cout<<"nn请输入要查找的航班号nn";
cin>>m;
while(p1)
{
if(strcmp(p1->getnu(),m)==0)
{
y1=0;
cout<<"n|---------------------------------------------------------------------------|n";
cout<<"n 航次:"<<p1->getnu()<<"起飞时间:"<<p1->gett()<<"总票数:"<<p1->getsu();
cout<<"n 航线:"<<p1->gets()<<"--->"<<p1->gete()<<"剩余票数:"<<p1->getn();
cout<<"n|---------------------------------------------------------------------------|n";
}
p1=p1->getnext();
}
if(y1)cout<<"n失败,您查询的航班不存在!n";
else{
while(p2)
{
if(strcmp(p2->getnu(),m)==0)
{
cout<<"n乘客姓名:"<<p2->getna()<<"所购机票数:"<<p2->getn();y2=0;
cout<<"n|---------------------------------------------------------------------------|n";
}
p2=p2->getnext();
}
if(y2)cout<<"n无任何乘客! n ";
}
}
break;
case '2':
{
Plan*p1=head1;
Client*p2=head2;
inty1=1,y2=1;
cout<<"nn请输入要查询姓名:nn";
cin>>m;
while(p2)
{
if(strcmp(p2->getna(),m)==0)
{
cout<<"n乘客姓名:"<<p2->getna()<<"所购机票数:"<<p2->getn();
y2=0;y2=0;
while(p1)
{
if(strcmp(p1->getnu(),p2->getnu())==0)
{
y1=0;
cout<<"n|---------------------------------------------------------------------------|n";
cout<<"n 航次:"<<p1->getnu()<<"起飞时间:"<<p1->gett()<<"总票数:"<<p1->getsu();
cout<<"n 航线:"<<p1->gets()<<"--->"<<p1->gete()<<"剩余票数:"<<p1->getn();
cout<<"n|---------------------------------------------------------------------------|n";
}
p1=p1->getnext();
}
if(y1)cout<<"失败,您查询的航班不存在!nn";
}
p2=p2->getnext();
}
if(y2)cout<<"失败,您查询的乘客不存在!nn";
}
break;
//case'3':
//return;
}
}while(c!='C'&&c!='c');
}


void manage::baClient()
{
if(head1==NULL){cout<<"nn提示:无航班信息!";return;}
if(head2==NULL){cout<<"nn提示:无乘客信息!";return;}
cout<<setw(20)<<"退机票n";
char m[30];
int y1=1,y2=1;
cout<<"n请输入您所买的航班nn";
cin>>m;
Plan *p1=head1;
while(p1)
{
if(strcmp(p1->getnu(),m)==0)
{
y1=0;
cout<<"nn请输入您的姓名:nn";
cin>>m;
Client*p2=head2;
while(p2)
{
if(strcmp(p2->getna(),m)==0)
{
y2=0;
loop:
cout<<"n您一共购买"<<p2->getn()<<"张机票!n请输入您退的票数!n";
ints;cin>>s;
if(p2->getn()<s)
{cout<<"n错误,您退的票数必须小于或者等于"<<p2->getn()<<"张!nn";gotoloop;}
else{p2->setn(p2->getn()-s);p1->setn(p1->getn()+s);}
}
p2=p2->getnext();
}
if(y2){cout<<"n错误,您并未购买此航班机票!n";return;}
}
p1=p1->getnext();
}
if(y1){cout<<"n错误,无此航班!n";return;}
cout<<"n退票成功!";
}


void manage::save()
{
ofstreamfile("plane.txt",ios::in,filebuf::openprot);
int n=0;
Plan *p1=head1;
while(p1){n++;p1=p1->getnext();}
file.write((char*)&n,sizeof(n));
p1=head1;
while(p1)
{
file.write((char*)p1,sizeof(Plan));
p1=p1->getnext();
}
cout<<"n保存"<<n<<"条航班信息成功!";
Client *p2=head2;
n=0;
while(p2){n++;p2=p2->getnext();}
file.write((char*)&n,sizeof(n));
p2=head2;
while(p2)
{
file.write((char*)p2,sizeof(Client));
p2=p2->getnext();
}
cout<<"n保存"<<n<<"条乘客信息成功!";
file.close();
}


void manage::run()
{
cout<<setw(35)<<"欢迎使用航空订票系统,请选择您所需的操作n";
cout<<setw(55)<<"n";
cout<<setw(45)<<"1,进入n";
cout<<setw(55)<<"n";
cout<<setw(45)<<"2,退出n";
int c;
cin>>c;
if(c==1)
{
cout<<"nnnnnnnnnn";
ini();
char c1;
do{
cout<<setw(20)<<"主菜单"<<endl;
cout<<endl;
cout<<setw(50)<<"请选择您所需的操作n";
cout<<setw(50)<<"n";
cout<<setw(35)<<"1,信息显示n";
cout<<setw(35)<<"2,买机票n";
cout<<setw(35)<<"3,退机票n";
cout<<setw(35)<<"4,信息查询n";
cout<<setw(35)<<"5,系统管理n";
cout<<setw(35)<<"6,清空数据n";
cout<<setw(35)<<"0,退出n";
cout<<endl;
cin>>c1;
switch ( c1)
{
case'1':
{
charcc1;
do{
cout<<"导航菜单1:航线导航 2:乘客导航0:退出=>"<<endl;
cin>>cc1;
switch(cc1)
{
case'1':
show1();break;
case'2':
show2();break;
case'0':
break;
}
}while(cc1!='0');
}break;
case'2':
buy();break;
case'3':
baClient();break;
case'4':
{charcc1;
do{
cout<<"查询菜单1:航线查询 2:乘客查询0:退出=>"<<endl;
cin>>cc1;
switch(cc1)
{
case'1':
query1();break;
case'2':
query2();break;
case'0':break;
}
}while(cc1!='0');
}break;
case'5':
{
charc2;
do{
cout<<"航班管理1:新增 2:更改 3:删除0:退出=>"<<endl;
cin>>c2;
switch(c2)
{
case'1':newf();break;
case'2':modify();break;
case'3':del();break;
case'0':break;
}
}while(c2!='0');
}break;
case'6':
delall();break;}
}
while(c1!='0');
cout<<"nn谢谢您的使用!";
save();
}
else ;
}


void main()
{

manage* p;
p->run();
}

//JuLY/整理/06.02/。

  

爱华网本文地址 » http://www.413yy.cn/a/25101013/149846.html

更多阅读

重装系统详细步骤及注意事项以Windows7为例 u盘重装系统步骤

重装系统详细步骤及注意事项(以Windows7为例)——简介重装系统很多人都经历过,但有很多人自己并不会重装系统,其实重装系统很简单,下面就来给大家详细的讲一下如何重装系统。下面讲的方法是最简单而且最通用的方法,基本上绝大多数的商场

C/S与B/S系统测试的不同点和相同点 全国名字相同查询系统

A回答.按系统测试的分类1.功能性测试C/S:服务器和客户端均会分担一部分的事务处理功能,应分开测试。B/S:服务器负责主要的事务逻辑,所以应将重点放在服务器上。2.安全测试C/S:可以使用多种网络协议,甚至可以自定义协议,从这个角度来看,C/S的

DNF佣兵系统详细介绍 dnf支援兵系统详细介绍

DNF佣兵系统详细介绍——简介早在不知道什么时候,DNF推出了佣兵系统,到底是什么玩意呢?DNF佣兵系统详细介绍——DNF佣兵系统:DNF佣兵系统详细介绍 1、在某次版本更新以后,DNF就推出了佣兵系统。DNF佣兵系统在哪?我们可以看到屏幕的右下

声明:《c++设计航班订票系统 航空订票系统详细设计》为网友写给山河水月分享!如侵犯到您的合法权益请联系我们删除