免费vc++航空客运订票系统+论文(一)

时间:2021-03-20 15:16:32 计算机毕业论文 我要投稿

免费vc++航空客运订票系统+论文(一)

航空客运订票系统
1  问题描述 
  航空客运订票的业务活动包括:查询航线、客票预订和办理退票等。试设计一个航空客运订票系统,以使上述业务可以借助计算机来完成。
1.1 每条航线所涉及的信息有:终点站名、航班号、飞机号、飞行周日(星期几)、乘员定额、余票量、已订票的客户名单(包括姓名、订票量、舱位等级1,2或3)以及等候替补的客户名单(包括姓名、所需票量)
1.2 作为示意系统,全部数据可以只放在内存中
1.3 系统能实现的操作和功能如下:
1.3.1 查询航线:根据旅客提出的终点站名输出下列信息:航班号、飞机号、星期几飞行,最近一天航班的日期和余票额
1.3.2 承办订票业务:根据客户提出的要求(航班号、订票数额)查询该航班票额情况,若尚有余票,则为客户办理订票手续,输出座位号;若已满员或余票额少于订票额,则需重新询问客户要求。若需要,可登记排队候补
1.3.3 承办退票业务:根据客户提供的情况(日期、航班),为客户办理退票手续,然后查询该航班是否有人排队候补,首先询问排在第一的客户,若所退票额能满足他的要求,则为他办理订票手续,否则依次询问其他排队候补的客户
2  概要设计
2.1 存储结构设计
typedef struct Al_Custom //已订票客户
{
 char name[15];//姓名
 int count;//订票量
 int level;//舱位等级
 Al_Custom *next;//下一节点指针
}Al_Custom,*Al_CustomLink;

免费vc++航空客运订票系统+论文(一)

typedef struct Wait_Custom//等候替补的客户
{
 char name[15];//姓名
 int count;//所需票量
 Wait_Custom *next;//下一节点指针
}Wait_Custom;

typedef struct Wait_Queue//等待队列
{
 Wait_Custom *front;//队列头指针
 Wait_Custom *rear;//尾指针
}Wait_Queue;

typedef struct Flight//航线
{
 char terminus[15];//终点站名
 char flight_no[10];//航班号
 char plane_no[10];//飞机号
 int week;//飞行周日
 int count;//乘客定额
 int rest;//余票量
 Al_CustomLink Al_link;//指向成员名单链表的头指针
 Wait_Queue wait_queue;//等待替补队列
}Flight;
2.2 主要算法设计
2.2.1 主程序模块:
void main()
{
   初始化;
   do{
     接受命令;
     处理命令;
     }while(命令!="退出");
}
2.2.2  查询航线模块——实现查询功能
void findFlight()
{
    提示输入要查询航线的终点站名;
    如果存在该航线,则输出该航线信息;
    否则提示不存在该航线;
}
2.2.3  承办订票业务模块——实现订票功能
void dingpiao()
{
    提示输入航班号和订票数;
    若不存在该航班号,则提示不存在该航线;
    否则{
         如果有余票,则办理业务;
         否则提示没有足够的余票,询问是否候补;
         若是,则排队候补;
        }
}
2.2.4  承办退票业务模块——实现退票功能
void tuipiao()
{
     提示输入航班号和飞行周日;
     确认航班号和飞行周日都存在,并且客户有订票,
     则  {执行退票;
         为排队候补的客户办理订票业务;
         }
     否则{
          提示有误
  }
}
2.3  测试用例设计
2.3.1  航线3条:1001    hp001   shanghai  2   50
                    1002    hp002   beijing   5   50
                    1003    hp003   guangzhou 7   50
2.3.2  查询航线:shanghai
 2.3.3  承办订票业务:航班号1001  数额30  姓名chengangjie 舱位等级2
 2.3.4  承办订票业务:航班号1001  数额23  姓名zhenxi      舱位等级3
2.3.5  承办退票业务:姓名chengangjie 航班号1001 飞行周日2
2.3.6  查询航线:终点站名:shanghai
3  调试分析
3.1 本次的设计比较困难,需要实现较多的功能,所以在调试过程中不太顺利,主要是指针的修改。经过反复调试以后才得以解决。
3.2 本程序航线采用数组的存储结构,每条航线包含8个域,其中乘员名单域为指向乘员名单链表的头指针,等候替补的客户名单域为分别指向对头和对尾的指针。
3.3 订票函数是在退票业务模块中使用
4  经验和体会
通过这次的程序设计,进一步理解了链表和队列结构的实现和应用。尤其需要注意的是:对于指针的修改要仔细,否则会发生意想不到的结果。
5  源程序清单和运行结果
5.1 程序清单
#include<iostream.h>
#include<iomanip.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
#define FLIGHT_NUM 100//航线最大数量

typedef struct Al_Custom //已订票客户
{
 char name[15];//姓名
 int count;//订票量
 int level;//舱位等级
 Al_Custom *next;//下一节点指针
}Al_Custom,*Al_CustomLink;

typedef struct Wait_Custom//等候替补的客户
{
 char name[15];//姓名
 int count;//所需票量
 Wait_Custom *next;//下一节点指针
}Wait_Custom;

typedef struct Wait_Queue//等待队列
{
 Wait_Custom *front;//队列头指针
 Wait_Custom *rear;//尾指针
}Wait_Queue;

typedef struct Flight//航线
{
 char terminus[15];//终点站名
 char flight_no[10];//航班号
 char plane_no[10];//飞机号
 int week;//飞行周日
 int count;//乘客定额
 int rest;//余票量
 Al_CustomLink Al_link;//指向成员名单链表的'头指针
 Wait_Queue wait_queue;//等待替补队列
}Flight;

void Custom_init(Al_CustomLink &L)
{
 L=new Al_Custom;
 L->next=0;
}

void Custom_insert(Al_CustomLink &L,Al_Custom& custom)
{
 Al_Custom *p=L,*newnode=new Al_Custom;
 memcpy((void*)newnode,&custom,sizeof(Al_Custom));
 newnode->next=p->next;
 p->next=newnode;
}

void copyCustomLink(Al_CustomLink &dest,Al_CustomLink &source)//复制已订票客户链表
{
 Al_CustomLink p=source;
 Al_CustomLink q;
 Al_Custom *pnew;
 Custom_init(dest);
 q=dest;
 while(p->next)
 {
  pnew=new Al_Custom;
  memcpy(pnew,p->next,sizeof(Al_Custom));
  pnew->next=0;
  q->next=pnew;
  q=pnew;
  p=p->next;
 }
 
}

void Waiter_init(Wait_Queue &Q)
{
 Q.front=Q.rear=new Wait_Custom;
 Q.front->next=0;
}

void Waiter_En(Wait_Queue &Q,Wait_Custom& custom)
{
 Wait_Custom *newnode=new Wait_Custom;
 memcpy(newnode,&custom,sizeof(Wait_Custom));
 newnode->next=0;
 Q.rear->next=newnode;
 Q.rear=newnode;
}
bool Waiter_De(Wait_Queue &Q,Wait_Custom& custom)
{
 if(Q.rear==Q.front)
  return false;
 memcpy(&custom,Q.front,sizeof(Wait_Custom));
 Wait_Custom *p=Q.front->next;
 Q.front->next=p->next;
 if(Q.rear!=Q.front)
  Q.rear=Q.front;
 delete p;
 custom.next=0;
 return true;
}


void copyWait_Queue(Wait_Queue &dest,Wait_Queue& source)//复制等待队列
{
 Wait_Custom *p=source.front;
 Waiter_init(dest);
 while(p->next)
 {
  Waiter_En(dest,*p);
  p=p->next;
 }
}


int flight_no;//航线数量
Flight flight[FLIGHT_NUM];//航线数组

void initFlight(Flight &f)//初始化一条航线
{
 char ch=0;
 strncpy((char*)&f,&ch,sizeof(Flight));
 Custom_init(f.Al_link);
 Waiter_init(f.wait_queue);
}

void initFlight()//初始化航线数组
{
 flight_no=0;
 char ch=0;
 strncpy((char*)flight,&ch,FLIGHT_NUM*sizeof(Flight));
 for(int i=0;i<FLIGHT_NUM;i++)
 {
  Custom_init(flight[i].Al_link);
  Waiter_init(flight[i].wait_queue);
 }
}

void insertFlight(Flight& f)//按终点站名有序插入航线到航线数组
{
 int i=-1;
 while(i+1<flight_no && strcmp(f.terminus,flight[i+1].terminus)==1)
 {
  i++;
 }
 for(int j=flight_no-1;j>=i+1;j--)
 {
  memcpy((void*)(&(flight[j+1])),(void*)(&(flight[j])),sizeof(Flight));
 }
 memcpy((void*)(&(flight[i+1])),(void*)(&f),sizeof(Flight));
 Custom_init(flight[i+1].Al_link);
 Waiter_init(flight[i+1].wait_queue);
 copyCustomLink(flight[i+1].Al_link,f.Al_link);
 copyWait_Queue(flight[i+1].wait_queue,f.wait_queue);
 flight_no++;
}

void init()
{
 int m;
 cout<<"请输入航线条数:";
 cin>>m;
 for(int i=1;i<=m;i++)
 {
  Flight f;
  initFlight(f);
  cout<<"输入第"<<i<<"条航线:"<<endl;
  cout<<"航班号:";
  cin>>f.flight_no;
  cout<<"飞机号:";
  cin>>f.plane_no;
  cout<<"终点站名:";
  cin>>f.terminus;
  cout<<"飞行周日:";
  cin>>f.week;
  cout<<"成员定额:";
  cin>>f.count;
  f.rest=f.count;
  insertFlight(f);
  printf("\n");
 }
}
int findbyname(char terminus[15])//根据终点站名查找
{
 for(int i=0;i<flight_no;i++)
 {
  if(strcmp(flight[i].terminus,terminus)==0)
  {
   return i;
  }
 }
 return -1;
}

int findbyno(char no[10])//根据航班号查找
{
 for(int i=0;i<flight_no;i++)
 {
  if(strcmp(flight[i].flight_no,no)==0)
  {
   return i;
  }
 }
 return -1;
}


void findFlight()//查询航线子模块
{
 char terminus[15];
 cout<<"请输入要查询航线的终点站号:";
 cin>>terminus;
 int index=findbyname(terminus);
 if(index==-1)
 {
  printf("该航线不存在!\n");
  return ;
 }
 cout<<setw(12)<<"航班号"<<setw(12)<<"飞机号"<<setw(12)<<"飞行周日"<<setw(12)<<"余票额"<<endl;
 cout<<setw(12)<<flight[index].flight_no
  <<setw(12)<<flight[index].plane_no
  <<setw(12)<<flight[index].week
  <<setw(12)<<flight[index].rest<<endl<<endl;
}

void dingpiao(int index)
{

 Wait_Custom *p=flight[index].wait_queue.front;
 while(p!=flight[index].wait_queue.rear)
 {
  if(p->next->count<=flight[index].count)
  {
   cout<<"为"<<p->next->name<<"办理订票手续"<<endl;
   Al_Custom *pnew=new Al_Custom;
   pnew->count=p->next->count;
   flight[index].rest-=p->next->count;
   strcpy(pnew->name,p->next->name);
   do{
    cout<<"请"<<p->next->name<<"输入所需要的舱位等级(1-3):";
    cin>>pnew->level;
   }while(pnew->level<1 || pnew->level>3);
   pnew->next=flight[index].Al_link->next;
   flight[index].Al_link->next=pnew;
   Wait_Custom *q=p->next;
   p->next=q->next;
   
   if(flight[index].wait_queue.rear==q)
    flight[index].wait_queue.rear=p;
   delete q;
  }
 }
}

void dingpiao()//承办订票业务子模块
{
 char no[10];//航班号
 int count;//订票量
 cout<<"请输入航班号和订票数额:";
 cin>>no>>count;
 int index=findbyno(no);
 if(index==-1)
 {
  cout<<"该航线不存在"<<endl;
  return ;
 }
 if(flight[index].rest>=count)//尚有余票
 {
  Al_Custom *pnew=new Al_Custom;
  cout<<"请输入您的姓名:";
  cin>>pnew->name;
  cout<<"请输入您要订的舱位等级:";
  cin>>pnew->level;
  pnew->count=count;
  pnew->next=0;
  flight[index].rest-=count;
  pnew->next=flight[index].Al_link->next;
  flight[index].Al_link->next=pnew;
 }
 else//没有余票
 {
  cout<<"该航班的余票额不能满足您的要求,是否排队候补(y/n):";
  cout.flush();
  char select;
  do{
   select=getch();
  }while(select!='y' && select!='n');
  if(select=='y')//排队候补
  {
   Wait_Custom *pnew=new Wait_Custom;
   cout<<endl;
   cout<<"请输入您的姓名:";
   cin>>pnew->name;
   pnew->count=count;
   pnew->next=0;
   flight[index].wait_queue.rear->next=pnew;
   flight[index].wait_queue.rear=pnew;
   cout<<flight[index].wait_queue.rear->name<<endl;
  }
  else
  {
  }
 }
}

void tuipiao()//承办退票业务子模块
{
 cout<<"请输入您的姓名:";
 char name[15];
 cin>>name;
 cout<<"请输入你要退票的航班号与飞行周日:";
 int week;
 char no[10];
 cin>>no>>week;
 bool isfind=false;
 for(int index=0;index<flight_no;index++)
 {
  if(flight[index].week==week && strcmp(flight[index].flight_no,no)==0)
  {
   Al_Custom *p=flight[index].Al_link;
   while(p && p->next)
   {
    if(strcmp(p->next->name,name)==0)
    { 
     isfind=true;
     Al_Custom *q=p->next;
     p->next=q->next;
     {
      flight[index].rest+=q->count;
      cout<<flight[index].rest<<endl;
      dingpiao(index);//为第index条航线排队等候的客户办理订票手续
     }
     delete q;
    }
    p=p->next;
   }
  }
 }
 if(!isfind)
 {
  cout<<"您没有订该天该航班的票!"<<endl;
  return;
 }
 cout<<"退票成功!"<<endl;
}

void welcome()
{
 cout<<"选择操作:"<<endl;
 cout<<"              1.查询航线"<<endl;
 cout<<"              2.承办订票业务"<<endl;
 cout<<"              3.承办退票业务"<<endl;
 cout<<"              4.退出"<<endl;
}

void main()
{
 initFlight();
 init();
 char ch;
 do{
  welcome();
  do{
   ch=getch();
  }while(ch<'1' || ch>'4');
  switch(ch)
  {
  case '1':
   findFlight();
   break;
  case '2':
   dingpiao();
   break;
  case '3':
   tuipiao();
   break;
  case '4':
   break;
  }
 }while(ch!='4');
}
5.2 运行结果:
5.2.1 输入航线:
5.2.2 查询航线:
5.2.3 承办订票业务:
5.2.4 承办退票业务:

5.2.5查询航线:

【免费vc++航空客运订票系统+论文(一)】相关文章:

浅谈免费OA系统08-08

免费OA系统存在的风险08-16

免费OA系统该如何看待08-12

免费OA系统存在的缺陷08-10

VC++中的内联08-08

免费毕业论文范文08-08

2017飞机订票知识大全10-23

免费oa系统隐藏着哪些弊端08-14

关于日本留学订票常识介绍10-31

VC++两套笔试题目11-22