航班系统

#include <iostream.h>
#include <string.h>
void FlightInsert();
void FlightDelete();
void FlightLookup();
void FlightRework();
void FlightBuyticket();
void FlightCancelticket();
void Flightclean();
void MainMenu();

typedef struct Customer   //已定票乘客信息
{
 char Name[10];   //姓名
 int Amount;   //定票数
 int Level;   //舱位等级
 int SeatNum;   //座位号
 char FlightNum[10];   //所定航班号
 struct Customer *next;
}Customer;

typedef struct Replace   //替补乘客信息
{
 char Name[10];    //姓名
 int Amount;   //定票数
 int Level;   //舱位等级
 char FlightNum[100];   //所定航班号
 struct Replace *next; 
}Replace;  

typedef struct Flight   //航线信息
{
       char start_address[10];   //起飞站 
 char Des[10];   //终点站名
 char FlightNum[10];   //航班号
 char PlaneNum[10];   //飞机号
 char Week;   //飞行周日
 int Ration;   //乘员定额
 int FreeTicket[10];   //剩余票数
 float Price[3];   //舱位等级的价格
 int ReplacePas;   //候补乘客数
 Replace *ReplName;   //该航班的候补乘客名单     
 Customer *CustName;   //该航班的已定票乘客名单
 struct Flight *next;   //指示下一航线结点
}Flight,*PFlight;

int Ration=0;   //乘客总数
Flight *head;   //建立航线头结点
Flight *rear;   //建立航线尾结点  
Customer *Cusrear;
Replace *Reprear;

void MainMenu()
{
 char i='0';
 while (i!='8')
 {
  cout<<"       ***********航空公司客运订票系统V1.0***********"<<endl;
  cout<<"       *     1、增加航线               5、预订机票      *"<<endl;
  cout<<"       *     2、查询航线               6、退订机票      *"<<endl;
  cout<<"       *     3、修改航线               7、清空系统      *"<<endl;
        cout<<"       *     4、删除航线               8、退出系统      *"<<endl;
  cout<<"       **************************************************"<<endl;
  cin>>i;
  switch(i)
  {
  case '1':FlightInsert();break;
  case '2':FlightLookup();break;
        case '3':FlightRework();break;
  case '4':FlightDelete();break;
  case '5':FlightBuyticket();break;
  case '6':FlightCancelticket();break;
  case '7':Flightclean();break;
  case '8':;break;
  default:cout<<"error/n";break;
  }
 }
}

void  FlightInsert()   //航班插入
{
    Flight *p;
    p=new Flight;
    cout<<"请输入起点站名:"<<endl;
     cin>>p->Des;
    cout<<"请输入终点站名:"<<endl;
    cin>>p->Des;
    cout<<"请输入航班号:"<<endl;
    cin>>p->FlightNum;
    cout<<"请输入飞机号:"<<endl;
    cin>>p->PlaneNum;
    cout<<"请输入飞行周日:"<<endl;
    cin>>p->Week;
    cout<<"请输入乘员定额:"<<endl;
    cin>>p->Ration;
    p->FreeTicket[10]=p->Ration;
    cout<<"请输入舱位等级的价格:"<<endl;
    cout<<"头等舱价格"<<endl;
    cin>>p->Price[0];
    cout<<"普通舱价格"<<endl;
    cin>>p->Price[1];
    cout<<"经济舱价格"<<endl;
    cin>>p->Price[2];
    p->ReplName=new Replace;
    p->CustName=new Customer;
    p->CustName->next=NULL;
    p->ReplName->next=NULL;
    p->ReplacePas=0;
    rear->next=p;
    rear=p;
    rear->next=NULL;
}

void FlightDelete()   //删除航班
{
 Flight *p,*q;
 char FlightNum[10];
 p=head;
 int i=0;
 while (i!=1)
 {
  cout<<"请输入需要删除的航班号:"<<endl;
  cin>>FlightNum;
  while (p->next&&strcmp(p->next->FlightNum,FlightNum))
  {
   p=p->next;
  }    
  q=p->next;
  if (q!=NULL)
  {
   if(q->next==NULL)
   {    //当删除rear所指向的结点
    rear=p;
   }
            p->next=p->next->next;
   delete q;
  }
        else
  {
   cout<<"你所要删除的航班不存在"<<endl;
  }
  cout<<"1、退出2、继续"<<endl;
  cin>>i;
 }
}

void FlightLookup()   //查询航班
{
 Flight *p,*q;
 char FlightNum[10];
 p=head;
 int i=0;
 while (i!=1)
 {
  cout<<"请输入需要查询的航班号:"<<endl;
  cin>>FlightNum;
  while (p->next&&strcmp(p->next->FlightNum,FlightNum))
  {
   p=p->next;
  }
  q=p->next;
  if (q==NULL)
  {
   cout<<"对不起不存在此航班"<<endl;
  }
  else
  {
   cout<<"航班号:"<<q->FlightNum<<endl;
   cout<<"飞机号:"<<q->PlaneNum<<endl;
   cout<<"起飞地:"<<q->Des<<endl;
   cout<<"目的地:"<<q->Des<<endl;
   cout<<"飞行周日:"<<q->Week<<endl;
   cout<<"成员定额:"<<q->Ration<<endl;
   cout<<"剩余票数:"<<q->FreeTicket<<endl;
   cout<<"候补乘客数:"<<q->ReplacePas<<endl;
   cout<<"头等舱价格:"<<q->Price[0]<<endl;
   cout<<"普通舱价格:"<<q->Price[1]<<endl;
   cout<<"经济舱价格:"<<q->Price[2]<<endl;
  }
  cout<<"1、返回主菜单 2、继续"<<endl;
  cin>>i;
 }
}

void FlightRework()   //修改航线信息
{
 int Customer_Number ;
 Flight *p,*q;
 char FlightNum[10];
 char i='0';
 p=head;
 cout<<"请输入需要修改的航班号:"<<endl;
 cin>>FlightNum;
 while (p->next&&strcmp(p->next->FlightNum,FlightNum))
 {
  p=p->next;
 }
 q=p->next;
 if (q==NULL)
 {
  cout<<"对不起不存在此航班"<<endl;
 }
 else
 {
  while(i!='9')
  {
   cout<<"     *****请输入需要修改的数据*****"<<endl;
   cout<<"     *0、航班号        1、飞机号  *"<<endl;
            cout<<"     *2、起飞地        3、目的地  *"<<endl;
   cout<<"     *4、飞行周日     5、成员定额*"<<endl;
   cout<<"     *6、头等舱价格   7、普通舱价格*"<<endl;
            cout<<"     *8、经济舱价格    9、退出   *"<<endl;
   cout<<"     ******************************"<<endl;
   cin>>i;
   switch(i)
   {
   case '0':cout<<"请输入航班号:"<<endl;
       cin>>q->PlaneNum;break;
   case '1':cout<<"请输入飞机号:"<<endl;
                   cin>>q->PlaneNum;break;
                   case '2':cout<<"请输入起飞地:"<<endl;
                cin>>q->Des;break;
   case '3':cout<<"请输入目的地:"<<endl;
                cin>>q->Des;break;
   case '4':cout<<"请输入飞行周日:"<<endl;
                cin>>q->Week;break;
   case '5':cout<<"请输入乘员定额:"<<endl;
    Customer_Number=q->Ration-q->FreeTicket[200];
    cin>>q->Ration;q->FreeTicket[200]=q->Ration-Customer_Number;break;
   case '6':cout<<"请输入头等舱价格:"<<endl;
                cin>>q->Price[0];break;
   case '7':cout<<"请输入普通舱价格:"<<endl;
                cin>>q->Price[1];break;
   case '8':cout<<"请输入经济舱价格:"<<endl;
                 cin>>q->Price[2];break;
         case'9': 
                    break;
         default:cout<<"error/n";break;
cin>>i;
            }
       }
 }
}

void FlightBuyticket() //订票
{
 int Ticket_Amount;
 void Buyticket(PFlight ,int );
 void Buyreplace(PFlight ,int ,int );
 Flight *p,*q;
 char Des[10];
 int i=2;
 while (i!=1)
 {  
        cout<<"请输入起飞地:"<<endl;
   ;
cin>>Des;
  cout<<"请输入目的地:"<<endl;
  cin>>Des;
        p=head;
  while (p->next&&strcmp(p->next->Des,Des))
  {
   p=p->next;
  }
  q=p->next;
  if (q==NULL)
  {
   cout<<"对不起不存在此航班"<<endl;
  }
  else
  {
   while(i!=1)
   {
    cout<<"输入需要够买的票数"<<endl;
    cin>>Ticket_Amount;
    while(Ticket_Amount==0)
    {
     cout<<"请输入一个非零数:"<<endl;
     cin>>Ticket_Amount;
    }
    if (Ticket_Amount<=q->FreeTicket[10])
    {
     Buyticket(q,Ticket_Amount);
    }
    else
    {
     int n;
     cout<<"剩余票数小于定票数,是否需要列入候补名单?(1、是 2、否)"<<endl;
     cin>>n;
     Buyreplace(q,Ticket_Amount,n);
    }
    cout<<"1、返回主菜单 2、继续"<<endl;
    cin>>i;
   }
  }
 }
}
   
void FlightCancelticket()   //退票
{
 
 void Buyticket(PFlight ,int );
 Flight *p,*q;
 Customer *h,*j;
 char FlightNum[6];
 char Customer_Name[10];
 int Replace1_Amount;   //候补第一个人的定票数
 int i;
 while (i!=1)
 {
  cout<<"请输入需要退定的航班号:"<<endl;
  cin>>FlightNum;
  p=head;
  while (p->next&&strcmp(p->next->FlightNum,FlightNum))
  {
   p=p->next;
  }
  q=p->next;
  if (q==NULL)
  {
   cout<<"对不起不存在此航班"<<endl;
  }
  else
  {
   while (i!=2)
   {
    cout<<"请输入姓名:"<<endl;
    cin>>Customer_Name;
    h=q->CustName;
    while (h->next&&strcmp(h->next->Name,Customer_Name))
    {
     h=h->next;
    }
    j=h->next;
    if(j==NULL)
    {
     cout<<"查无此人"<<endl;
    }
    else
    {
     if(j->next==NULL){    //当删除最后一个结点
      Cusrear=h;
     }
     h->next=h->next->next;
     q->FreeTicket[10]+=j->Amount;
     delete j;
     cout<<"删除成功!"<<endl;
     if(q->ReplName->next!=NULL)
     {
      Replace1_Amount=q->ReplName->next->Amount;
      if (Replace1_Amount<=q->FreeTicket[10])
      {
       Replace *rep;
       rep=q->ReplName->next;
       Customer *Cus2;
       Cus2=new Customer;
       Cus2->SeatNum=q->Ration-q->FreeTicket[10]+1;
       strcpy(Cus2->FlightNum, q->FlightNum );
       strcpy(Cus2->Name, rep->Name );
       Cus2->Amount=rep->Amount;
       Cus2->Level=rep->Level;
       cout<<"乘客"<<rep->Name<<"已经成功买票 "<<endl;
       cout<<"座位号为:";
       for(int i=1;i<=(rep->Amount);i++)
       {
        cout<<Cus2->SeatNum++<<" ";
       }
       cout<<endl;
       if (q->CustName->next==NULL)
       {
        Cusrear=q->CustName;
        Cusrear->next=Cus2;
        Cusrear=Cus2;
        Cusrear->next=NULL;
       }
       else
       {
        Cusrear->next=Cus2;
        Cusrear=Cus2;
        Cusrear->next=NULL;
       }
       q->FreeTicket[10]-=rep->Amount;
       q->ReplName->next=q->ReplName->next->next;
       q->ReplacePas--;
       delete rep;
      }
     }
    }
    cout<<"2、退出姓名录入"<<endl;
    cin>>i;
   }
  }
  cout<<"1、返回主菜单"<<endl;
  cin>>i;
 }
}

void Flightclean()
{
 head->next=rear->next;
 cout<<"系统已经清空!"<<endl;
}

void Buyticket(PFlight q,int Ticket_Amount)   //买票
{
 
 int n=Ticket_Amount;
 Customer *Cus2;
 Cus2=new Customer;
 Cus2->SeatNum=q->Ration-q->FreeTicket[10]+1;
 strcpy(Cus2->FlightNum, q->FlightNum );
 Cus2->Amount=Ticket_Amount;
 cout<<"请输入姓名:"<<endl;
 cin>>Cus2->Name;
 cout<<"请输入舱位等级:"<<endl;
 cin>>Cus2->Level;
 cout<<"你的座位号为"<<endl;
 for(int i=1;i<=Ticket_Amount;i++)
 {
  cout<<Cus2->SeatNum++<<" ";
 }
 cout<<endl;
 if (q->CustName->next==NULL)
 {
  Cusrear=q->CustName;
  Cusrear->next=Cus2;
  Cusrear=Cus2;
  Cusrear->next=NULL;
 
 }
 else{
  Cusrear->next=Cus2;
  Cusrear=Cus2;
  Cusrear->next=NULL;
 }
    q->FreeTicket[10]-=Ticket_Amount;
}

void Buyreplace(PFlight q,int Ticket_Amount,int n)   //进入候补队列
{
 Replace *Rep2;
 Rep2=new Replace;
 if(n==1)
 {
  q->ReplacePas+=Ticket_Amount;
  strcpy(Rep2->FlightNum,q->FlightNum);
  Rep2->Amount=Ticket_Amount;
  cout<<"请输入姓名:"<<endl;
  cin>>Rep2->Name;
  cout<<"请输入舱位等级(1-3):"<<endl;
        cin>>Rep2->Level;
  if(q->ReplName->next==NULL)
  {
   Reprear=q->ReplName;
   Reprear->next=Rep2;
   Reprear=Rep2;
            Reprear->next=NULL;
  }
  else{
   Reprear->next=Rep2;
            Reprear=Rep2;
   Reprear->next=NULL;
  }
 }
}


int main()  //主程序
{
 Cusrear=new Customer;
 Reprear=new Replace;
 head=rear=new Flight;
 head->next=NULL;
 MainMenu();
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值