⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 课设.cpp

📁 航空订票系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <iostream.h>
#include <process.h>
#include <string.h>
#include <conio.h>
#include <stdio.h>
#include <iomanip.h>
#define MAX 50
#define NULL 0
typedef struct Customer                //已定票乘客信息
{
   char Name[7];                    //姓名
   int Amount;                    //定票数
   char Rank;                        //舱位等级
   int Seat_No;                    //座位号
   struct Customer *Next;
}Customer;
typedef struct Replace                //替补乘客信息
{
   char Name[7];                    //姓名
   int Amount;                    //定票数
   char Rank;                        //舱位等级
   char Seat_No;                    //座位号
   struct Replace *Next;
}Replace,*PReplace;    
typedef struct Flight                //航线信息
{
   char Des_Name[10];                //终点站名
   char Flight_No[6];                //航班号
   char Plane_No[6];                //飞机号
   char Week_Day;                    //飞行周日
   int Customer_Amount;            //乘员定额
   int Free_Amount;                //剩余票数
   float Price[3];                //舱位等级的价格
   Replace *ReplName;                //该航班的候补乘客名单
   Customer *CustName;                //该航班的已定票乘客名单
   struct Flight *Next;            //指示下一航线结点
}Flight,*PFlight;
int Customer_Count=0;                //所有航线的定票乘客总数
Flight *Head;                        //航线头指针
Flight *p2;                        //航线结点指针
Customer *Custp1[MAX];                //各条航线乘客结点指针
Replace *Replp1[MAX];                //各条航线候补结点指针
int IsEmpty=1;                        //是否有定票乘客
int IsReplace=1;                    //是否有候补乘客
Customer *prior;                    //满足要求的定票乘客的前结点,以作删除操作

//---------------菜单模板函数---------------
char ModelMenu(char *s[],int Itemcount)
{
       int i;
       char answer;
       system("cls");
       cout<<"\n\n";
       cout<<"\t\t\t                                "<<endl;
       cout<<"\t\t\t"<<s[0]<<endl;
       cout<<"\t\t\t                                "<<endl;
       cout<<"\t\t\t                                "<<endl;
       cout<<"\t\t\t                                "<<endl;
       for(i=1;i<Itemcount;i++)
       {
           cout<<"\t\t\t"<<s[i]<<endl;
           if(i+1!=Itemcount)
       cout<<"\t\t\t                                "<<endl;
       }
       cout<<"\t\t\t                                "<<endl;
       cout<<"\t\t\t                                "<<endl;    
       cout<<"\t\t\t 输入菜单项";
       cin>>answer;
       return answer;
}
//---------------主菜单函数---------------
char MainMenu()
{
   char *MenuItem[]={"火车客运订票系统菜单  "," [1]. 列 车 增 加      ",\
       " [2]. 订 票 办 理      "," [3]. 退 票 办 理      "," [4]. 乘 客 管 理      ",\
   };
   return ModelMenu(MenuItem,6);
}

//---------------是否继续函数---------------
char Continue() 
{
   int i;
   char answer;
   while(1)
   {    
       cout<<"\t\t   ";
       for(i=0;i<15;i++)
           cout<<" ";
       cout<<"\n\t\t\t   是否继续(Y/N)?";
       cin>>answer;
       if(answer=='y'||answer=='Y')
           return 'y';
       else if(answer=='n'||answer=='N')
           return 'n';
       else
               cout<<"\t\t\t 输入错误,请重新输入!"<<endl;
   }
}
//---------------操作出错函数---------------
void ErrorMess()
{
   cout<<"\n\t\t\t对不起,没有相关菜单项,按任意键继续..."<<endl;
   getch();
}
//-----------------系统退出-----------------
int ExitSystem()
{
   char answer;
   cout<<"\n\t\t\t 你确定是否真要离开系统吗(Y/N)?";
   cin>>answer;
   if(answer=='y'||answer=='Y')
       return 1;
   else
       return 0;
}
//--------------操作提示函数-------------
void prefix(char *Item)
{
   int i;    
   system("cls");
   cout<<"\n\n\t\t\t      "<<Item<<endl;
   cout<<"\t\t   ";
   for(i=0;i<15;i++)
       cout<<" ";
   cout<<endl;
}
//--------------航线查找函数-------------
//Find_Line()为重载函数
int Find_Line(PFlight L,char *key)//引用调用
{
   int flag=0;   //该标志位0表示未找到相关信息,反之即找到,以下标志位同理
   Flight *p1;
   p1=L;            //赋航线首地址
   if(p1==p2)        //首航线不作比较
       return flag;
   while(p1!=p2&&p1!=NULL)    //本航班号不纳入比较范围,否则会一直提示航线不唯一
   {
       if(strcmp(p1->Flight_No,key)==0)
       {
           flag=1;
           break;
       }
       p1=p1->Next;//指向下一航班结点
   }
       return flag;
}
int Find_Line(PFlight L,char *key,PFlight &p2,int &Flight_No)//引用调用
{
   int flag=0;   //该标志位0表示未找到相关信息,反之即找到
   Flight *p1;
   p1=L;            //赋航线首结点
   while(p1!=NULL)    
   {
       if(strcmp(p1->Flight_No,key)==0)//不包括当前航线
       {
           flag=1;
           p2=p1;
           break;
       }
       p1=p1->Next;                    //指向下一航班结点
       if(p1!=NULL)                //遇结束符不作统计范围
           Flight_No++;
   }
   return flag;
}
//-----------------航线添加函数-------------
void Line_Add()
{
   Flight *p1;    //建立临时航线结点
   while(1)
   {
       if(Head==NULL)//航线为空
       {
           p1=p2=new Flight;    //建立首个航线
           Head=p2;
       }
       else
       {
           p1=new Flight; //建立航线结点
           p2->Next=p1;   //前一航线结点指向当前航班结点
           p2=p1;           //保留当前航班结点地址    
       }
       prefix("设置路线");
       cout<<"\t\t\t   设置终点站名:";
       cin>>p2->Des_Name;   
       while(1)            //数据合法性检验
       {
           cout<<"\n\t\t\t   设置列车号:";
           cin>>p2->Flight_No;
           if(Find_Line(Head,p2->Flight_No))   //存在航班号
               cout<<"\n\t\t\t   输入的航班号不唯一!"<<endl;
           else
               break;
       }


       cout<<"\n\t\t\t   列车定额:";
       cin>>p2->Customer_Amount;
       cout<<"\n\t\t\t   卧铺票价:";
       cin>>p2->Price[0];
       cout<<"\n\t\t\t   软座票价:";
       cin>>p2->Price[1];
       cout<<"\n\t\t\t   硬座票价:";
       cin>>p2->Price[2];
       p2->Free_Amount=p2->Customer_Amount;     //剩余票数与乘员定额相同
       p2->CustName=NULL;                         //该航线定票乘客头指针为空
       p2->ReplName=NULL;                         //初始候补名单为空 
       if(Continue()=='n')
       {
           p2->Next=NULL;                         //航线的下一结点为空
           return;
       }
   }
}
//------------航线是否为空函数-------------
int Empty_Flight()
{
   if(Head==NULL)
   {
       system("cls");
       cout<<"\n\n\n\n\n\n\n\n\t\t   SORRY,没有相关航线。按任意键返回..."<<endl;
       getch();
       return 1;
   }
   else
       return 0;
}
//------------航线查看函数-----------------
void Line_See()
{
   int Day;
   Flight *p1;
   p1=Head;
   char *Week_Day[]={"星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
   if(Empty_Flight())    //航班线为空
       return;
   prefix("订票统计");
  
   cout<<"                                        票   价         "<<endl;
   cout<<" 终点站名 列车号 乘员定额 剩余票数                 "<<endl;
   cout<<"                                 卧铺 软座 硬座 "<<endl;
  
   while(p1!=NULL)
   {
       Day=p1->Week_Day-'0'-1;//数字转换相应星期数 
       cout<<"  "<<setiosflags(ios::left)<<setw(8)<<p1->Des_Name<<" "<<setw(6)<<p1->Flight_No<<\
       " "<<setw(6)<<p1->Plane_No<<    " "<<setw(8)<<Week_Day[Day]<<    "│   "<<setw(5)<<p1->Customer_Amount<<\
       "    "<<setw(5)<<p1->Free_Amount<<"│"<<setw(4)<<p1->Price[0]<<"│"<<setw(4)<<p1->Price[1]<<"│"<<setw(4)<<p1->Price[2]<<"│"<<endl;
       p1=p1->Next; 
       if(p1!=NULL)
               cout<<"          "<<endl;
   }
   cout<<"         "<<endl;
   cout<<"\n\t\t\t   按任意键返回子菜单..."<<endl;
   getch();
}
void Sub1Menu()
{
   char *MenuItem[]={"│   航空客运航线管理子菜单   │","│ │[1]. 航 线 增 设    │ │",\
       "│ │[2]. 航 线 查 看    │ │","│ │[3]. 返 回 主 菜 单 │ │"};
   while(1)
       switch(ModelMenu(MenuItem,4))
       {
           case '1':{Line_Add();break;}
           case '2':{Line_See();break;}
           case '3':{return;}
           default:{ErrorMess();}
       }
}
//---------------订票办理函数---------------
void Sub2Menu()
{
   int Ticket_Count,Seat_No,i,flag=0;
   int Flight_No=0;        //记录满足条件的航线的定票结点
   Flight *p1;                //记下满足条件的航线结点地址
   Customer *p2;            //临时性定票乘员结点
   Replace *p3;            //临时性候补乘员结点
   char answer[7];            //用户输入的航班数据
   char temp;
   int tag=0;                //候补乘客标志位
   int Amount;
   int IsRepl=0;            //是否执行候补操作标志位
   if(Empty_Flight())        //航班线为空
       return;
   while(1)
   {
       prefix("订票办理");
       flag=0;                //标志位清零以重新作出判断
       Flight_No=0;
       tag=0;
       cout<<"\n\t\t\t   请输列车号:";
       cin>>answer;
       if(Find_Line(Head,answer,p1,Flight_No))        //调用航线查找函数,若存在则进行以下操作
       {
           while(1)                                //数据合法性检验
           {
               cout<<"\n\t\t\t   请输入定票数:";
               cin>>Ticket_Count;
               if(Ticket_Count==0)
               {
                   cout<<"\n\t\t\t请输入大于零的数,按任意键继续输入."<<endl;
                   getch();
               }
               else
                   break;
           }
           if(p1->Free_Amount>=Ticket_Count)
           {    
               Customer_Count++;                         //定票乘客总数增1
               flag=1;                                     //表明进入了订票实际操作
               IsRepl=1;                                 //定票量满足,无需进入候补操作
               Amount=p1->Free_Amount;                     //记录剩余票数 
               if(p1->CustName==NULL)                     //首个定票乘客,并记录相关属性
               {    
                   Custp1[Flight_No]=p2=new Customer;     //建立该航线的首位乘客结点
                   p1->CustName=Custp1[Flight_No];
               }
               else                                     //建立该航线的后续乘客结点
               {
                   p2=new Customer;    
                   Custp1[Flight_No]->Next=p2;
                   Custp1[Flight_No]=p2;
               }
                   IsEmpty=0;                                        //定票乘员不为空
                   Custp1[Flight_No]->Amount=Ticket_Count;            //订票数
                   Seat_No=p1->Customer_Amount-p1->Free_Amount+1;    //算出座位号
                   Custp1[Flight_No]->Seat_No=Seat_No;                //赋座位号
                   p1->Free_Amount-=Ticket_Count;                    //减去定票数

                   while(1)                                        //数据合法性检验
                   {
                       cout<<"\n\t\t\t   请输入座位类型(1-3):";
                       cin>>Custp1[Flight_No]->Rank;
                       if(!(Custp1[Flight_No]->Rank>='1'&&Custp1[Flight_No]->Rank<='3'))
                       {
                           cout<<"\n\t\t输入出错,请输入1-3之间的数,按任意键继续输入."<<endl;
                           getch();
                       }
                   else
                       break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -