航空管理系统
航空订票系统简单实现:
1、需求分析:
航班系统需求能根据客户输入的目的地查询相关航班信息,还能在此系统上面预定、取消航班。同时能浏览航班余票量等情况。综合上所述此题目的功能需求主要为:1.查询航班,2.订票.3.退票。
2、概要设计:
由于是针对于客户,所以我们这里就不再需要输入具体有哪些航班信息,我们可以采用默认有哪些航班在开放,利用数组进行存储。另外,订票模块是利用顺序表(链表)进行存储,毕竟预定人数未知,采用链表不用考虑上溢问题,退票模块是用链队,主要考虑到退票人员数目大,次序的先后顺序问题,这个需要采用“先申请先办理”,队列能处理这一问题。
程序大体形式为:先主程序,主程序界面提供多个模块的选择,每个模块对应相应的函数调用。我这里的预定函数和退票函数是分开的,一个为简单链表,一个为简单链队。但是他们都能对航班信息模块的信息进行更改。总的来说,此程序包含三个模块(1、航班信息2.客户信息。(预定信息在这个模块里面)3.退票信息)
3、详细设计:
以上为大致的流程图。每个模块后面有相应的函数调用。以下为主函数的源代码:
源文件:
#include<iostream>
#include"航班信息.h"
#include"客户信息.h"
#include"process.h"
#include<string>
using namespace std;
int main()
{
Bookdataly;
AirLineLY;
linkqueueLy;
system("cls");
intchioce;
do{
cout<< endl;
cout<< "\t\t\t 航空客运订票系统\n" << endl;
cout<< "\t\t---------------------------------\n";
cout<< "\t\t---------------------------------\n";
cout<< " ***1.航线信息***\n";
cout<< " ***2.预定信息(已预定、未预定、)***\n";
cout<< " ***3.查询航线***\n";
cout<< " ***4.订票办理***\n";
cout<< " ***5.退票办理***\n";
cout<< " ***6.退出系统***\n";
cout<< "\t\t----------------------------------\n";
cout<< "\t\t----------------------------------\n";
cout<< "\t\t----*****输入chioce:" <<" " << endl;
cin>> chioce;
switch(chioce)
{
case1:LY.Display(); break;//展现开设航班信息
case2://由于人员信息有两个,一个为未预定(表示需要退票的,),一个为已经预定的,另外已经预定了的,有已经预定了人员名单列表,当然,为了解决客户想看已预定中某个人的订单信息,这里还设置一个选择调用函数。进行功能满足。
{
int chioce;
do{
cout<< endl;
cout<< "\t\t\t *****预定信息界面*****\n" << endl;
cout<< "\t\t--------------------------------------\n";
cout<< "\t\t--------------------------------------\n";
cout<< " ***1.已经预定\n";
cout<< " ***2.未预定人员 \n";
cout<< " ***3.退出此系统 \n";
cout<< "\t\t--------------------------------------\n";
cout<< "\t\t--------------------------------------\n";
cout<< "----*****输入chioce:" <<" " << endl;
cin>> chioce;
switch(chioce)
{
case1:ly.Displaylinklist(); break;
case2:Ly.display(); break;
case3:
; break;
}
}while (chioce != 3);
}break;
case3:LY.Search(); break;//查找航班函数
case4:ly.Book(); break;//预定航班函数
case5:ly.Deletelinklist();//先在已经预链表上面删除此人,
Ly.enter(ly.name);//在队列上面入队此人名字
break;
case6:cout << "\n感谢使用本系统欢迎您下次使用!\n";
exit(0);
default:
cout<< "Invalid chioce!\n";
}
}while (chioce != 6);
return0;
}
头文件("航班信息.h")("客户信息.h")如下:
头文件:("航班信息.h")
//这里采用结构体数组存储默认已有航班
#include<iostream>
#include<string>
using namespace std;
#ifndef Airline_h
#define Airline_h
struct Airline{ //每个结构体中信息初始情况
intnumber;//航班编号
stringAirplane_number;//航班号
stringDestination_station;//终点站
intPlane_number;//飞机号
stringData;//飞行日期
doublePrice;//价格
intNotdata;//剩余未定
intAreadydata;//已定
}Airline[5] = {
{01,"TP45623", "济南", 23,"Monday", 956.0, 10, 31 },
{02,"TP46723", "北京", 06,"Sunday", 706.0, 04, 50 },
{03,"TP15723", "海南", 16,"Saturday", 718.0, 24, 11 },
{04,"BY961219", "美国", 04,"Monday", 2160.0, 4, 60 },
{05,"RM85462", "乌鲁木齐", 11,"Monday", 1080.0, 20, 20 }
};
//航班信息类
class AirLine{
public:
voidSearch();
voidDisplay();
};
void AirLine::Search(){ //航班查询函数
stringT;
inti;
cout<< "请输入要查询的目的地:" << endl;
cin>> T;
for(int i = 1; i <= 5; i++){
if(Airline[i].Destination_station == T)
{
cout<< "您所查找的航班:南通——>" << T <<" 的信息如下: " << endl;
cout<< "航班代号: " << Airline[i].number << endl;
cout<< "航班号: " << Airline[i].Airplane_number << endl;
cout<< "飞机号: " << Airline[i].Plane_number << endl;
cout<< "飞行日期:" << Airline[i].Data <<endl;
cout<< "价格: " << Airline[i].Price << endl;
cout<< "已定人数:" << Airline[i].Areadydata<< endl;
cout<< "剩余人数:" << Airline[i].Notdata<< endl;
}
}
cout<< "(输入:0) 返回主菜单:"<< endl;
cin>> i;
if(i == 0){
return;
}
}
//航班信息陈列函数
void AirLine::Display(){
system("cls");
inti;
cout<< "拥有的航班如下:" << endl;
for(int i = 0; i < 5; i++){
cout<< "<"<<i+1<<"> "<<"**南通————>"<<Airline[i].Destination_station << endl;
}
cout<< endl;
cout<< "(输入:0) 返回主菜单:"<< endl;
cin>> i;
if(i == 0){
return;
}
}
#endif
头文件2("客户信息.h")
#include<iostream>
#include"process.h"
#include<string>
using namespace std;
#ifndef Bookdata_h
#define Bookdata_h
//链表结点包含信息
struct Node{
stringName;
Node*next;
Node*pri;
intnumber;//航班编号
stringAirplane_number;//航班号
stringDestination_station;//终点站
intPlane_number;//飞机号
stringData;//飞行日期
doublePrice;//价格
intNotdata;//剩余未定
intAreadydata;//已定
};
//队列结点信息
struct Node2{
stringname;
Node2*next;
};
//预定航班类
class Bookdata{
private:
intI; //预定目的地代码
Node*head;
intk; //预定人数
stringyes, no;//确认信息的两种情况
Node2*front;
Node2*rear;
public:
stringT, name;
Bookdata();//链表构造函数
~Bookdata();//链表析构函数
voidPersoninformation();//个人预定航班信息函数
voidDisplaylinklist();//已定航班人员链表陈列函数
voidDeletelinklist();//列表人员铲除函数
void Book();//预定航班函数
voidEnterdata();//输入客户预定信息函数
voidconfirm();//客户订票确认函数
voidLook();//客户查看自己下单的订单函数
voidInsertlinklist();//在链表中插入一个新成员函数
voidsearch();//根据客户名字查找客户函数
};
class linkqueue{ //队列函数
private:Node2*front;
Node2*rear;
public:
linkqueue();
~linkqueue();
voidenter(string x);//入队函数
stringout();//出队函数;(注:此程序没有用到次函数,因为客户看到的是信息,而出队是系统处理人员的。)
voiddisplay();//陈列函数
};
linkqueue::linkqueue(){
front= new Node2;
front->next= NULL;
rear= front;
}
linkqueue::~linkqueue(){
Node2*p;
while(front != rear)
{
p= front;
front= front->next;
deletep;
}
}
void linkqueue::enter(string x){
Node2*s;
s= new Node2;
s->name= x;
s->next= rear->next;
rear->next= s;
if(front->next == NULL)
front->next= s;
}
string linkqueue::out(){
stringg;
Node2*p;
if(rear == front)throw"下溢";
p= front->next;
g= p->name;
if(p->next)
{
p= p->next;
if(p->next == NULL)rear = front;
cout<< p->name << "-->";
cout<< endl;
}
}
void linkqueue::display(){
Node2*p;
p= front->next;
cout<< "人员信息如下(包括退票人员):"<<endl;
cout<< "***********************"<<endl;
while(p){
intf = 1;
cout<< "("<<f<<")."<<p->name<< endl;
p= p->next;
f++;
}
cout<< "***********************"<< endl;
cout<< "(注:系统将按照序列大小进行退票:)" << endl;
cout<< "-----------------------" << endl;
cout<< "-----------------------" << endl;
cout<< endl;
}
void Bookdata::Enterdata(){
cout<< "---------------------"<<endl;
cout<< "请输入预定的目的地为: " << endl;
cin>> I;
cout<< "---------------------" << endl;
cout<< "请输入需要预定的人数为:" << endl;
cin>> k;
cout<< "---------------------" << endl;
cout<< "已自动返回,是否确认预定?" << endl;
cout<< "---------------------" << endl;
}
void Bookdata::Look(){
{
Node*p;
p= head;
for(p; p->Name != name&&p->next != NULL; p = p->next){
}
cout<< "***********************" << endl;
cout<< "个人订单信息如下:" << endl;
cout<< "姓名: " << p->Name<< endl;
cout<< "航班编号: " << p->number << endl;
cout<< "航班号: " << p->Airplane_number << endl;
cout<< "飞机号: " << p->Plane_number << endl;
cout<< "出发日期: " << p->Data << endl;
cout<< "终点站: " << p->Destination_station << endl;
cout<< "总计: " << p->Price << endl;
cout<< endl;
}
cout<< "返回预定菜单,请输入 “0”" << endl;
intx;
cin>> x;
if(x == 0)
return;
else
exit(0);
cout<< "*****************" << endl;
}
void Bookdata::Insertlinklist(){
Node*p,*q;
stringt;
p= head;
while(p->next != NULL){
p= p->next;
}
for(int i = 0; i<5; i++)
{
if(Airline[i].number == I)
{
//以下两行控制票量的增加或减少;
Airline[i].Areadydata= Airline[i].Areadydata + k; Airline[i].Notdata= Airline[i].Notdata - k;
cin>> name;
q= new Node;
q->Name= name;
q->Airplane_number= Airline[i].Airplane_number;
q->Plane_number= Airline[i].Plane_number;
q->Destination_station= Airline[i].Destination_station;
q->Data= Airline[i].Data;
q->number= Airline[i].number;
q->Price= Airline[i].Price*k;
q->next= p->next;
p->next= q;
q->pri= p;
}
}
cout<< endl;
}
void Bookdata::confirm(){
cout<< "****是否确认预定:(“是”请输入 yes,否则输入 no):"<< endl;
cin>> T;
cout<< "请输入名字为:" << " ";
Insertlinklist();
cout<< "***您已经成功预定!!!" << endl;
cout<< endl;
cout<< "\t\t返回预定菜单(请输入“0”)" << endl;
intx;
cin>> x;
if(x == 0)
return;
else
exit(0);
cout<< "*****************" << endl;
}
Bookdata::Bookdata(){
head= new Node;
head->next= NULL;
head->pri= NULL;
}
Bookdata::~Bookdata(){
Node*t;
while(head){
t= head;
head= head->next;
deletet;
}
head= NULL;
}
void Bookdata::Deletelinklist(){
cout<< "输入要查看的人的姓名:" << endl;
cin>>name;
Node*p, *q, *h;
p= head;
for(p; p->Name != name&&p->next != NULL; p = p->next){
}
h= p->pri;
q= p->next;
h->next= p->next;
q->pri= p->pri;
deletep;
cout<< "系统已经接收(" << name << ")客户的退票办理,注意查收消息!" << '\n' <<
"您可以在客户信息界面(预定界面)进行查看"<< endl;
cout<< endl;
}
void Bookdata::Displaylinklist(){
inti;
cout<< "已有已定人员列表如下:" << endl;
Node*p;
p= head;
while(p)
{
cout<< p->Name;
p= p->next;
cout<< "--";
}
cout<< endl;
cout<<"****************************"<< endl;
cout<< "是否查看个人订单详细情况?(是 输入:0,否 输入:1~9)" << endl;
cin>> i;
cout<<"****************************"<< endl;
if(i==0){
Personinformation();
}
else
{
return;
}
}
void Bookdata::search(){
cout<< "输入要查询人的姓名:" << endl;
cin>> name;
Node*p;
p= head;
for(p; p->Name != name&&p->next != NULL; p = p->next){
}
cout<< "***********************" << endl;
cout<< "个人订单信息如下:" << endl;
cout<< "姓名: " << p->Name<<endl;
cout<< "航班编号: " << p->number << endl;
cout<< "航班号: "<<p->Airplane_number<< endl;
cout<< "飞机号: " << p->Plane_number << endl;
cout<< "出发日期: "<<p->Data << endl;
cout<< "终点站: " << p->Destination_station << endl;
cout<< "总计: "<<p->Price << endl;
cout<< "***********************" << endl;
}
void Bookdata::Personinformation(){
intchioce;
do{
cout<< endl;
cout<< "\t\t\t *****个人信息*****\n" << endl;
cout<< "\t\t--------------------------------------\n";
cout<< "\t\t--------------------------------------\n";
cout<< " ***1.查看个人预定信息\n";
cout<< " ***2.退出此系统 \n";
cout<< "\t\t--------------------------------------\n";
cout<< "\t\t--------------------------------------\n";
cout<< "----*****输入chioce:" <<" " << endl;
cin>> chioce;
switch(chioce)
{
case1:search(); break;
case2:
intx;
cout<< "返回主菜单 请按“1”" << endl;
cin>> x;
if(x == 1)
return;break;
default:
cout<< "Invalid chioce!\n";
}
}while (chioce != 2);
}
void Bookdata::Book(){
intchioce;
do{
cout<< endl;
cout << "\t\t\t *****预定界面*****\n"<< endl;
cout<< "\t\t--------------------------------------\n";
cout<< "\t\t--------------------------------------\n";
cout<< " ***1.输入预定信息\n";
cout<< " ***2.确认预定 \n";
cout<< " ***3.查看信息 \n";
cout<< " ***4.退出此系统 \n";
cout<< "\t\t--------------------------------------\n";
cout<< "\t\t--------------------------------------\n";
cout<< "----*****输入chioce:" <<" " << endl;
cin>> chioce;
switch(chioce)
{
case1:Enterdata(); break;
case2:confirm(); break;
case3:Look(); break;
case4:
intx;
cout<< "返回主菜单 请按“1”" << endl;
cin>> x;
if(x==1)
return; break;
default:
cout<< "Invalid chioce!\n"; break;
}
}while (chioce != 4);
}
#endif
5、调试分析:
刚开始出现回不到主界面菜单的问题,,后来通过循环函数解决。
另外出现已定人员数目的增加,但是链表里面没有人员信息,后来通过调试,发现时对象调用错误。已经解决。
这里得通过队列和链表主要时间花在查找上面:时间复杂度为:n;
6、运行结果:
运行结果如上:可以发现预定航线里面剩余票量有变化;
7、总结与体会:
本次程序的敲写,主要是对一个系统的分析,对一些功能的如何用代码解决进行练习(主要是对需求的分析),存储利用数组和链表、队列。内容不难,但是容颜易出现一些小错误。用时1天。程序自我感觉有些小繁冗。由于自己的能力能将它做出来还是挺高兴。另外总结下,每一个大问题,是能分解为小问题的,每个小问题是需要考虑的部分为:1、这个小问题用什么样数据结构来解决,2、这个小问题需要怎样的存储(链式还是数组呢?)结构3、换作自己是客户或者使用人,有没有需要优化的地方、有没有没有考虑到的地方。是否简洁美观了。然后将每个小版块组合起来通过主函数调用。