链表(飞机航班系统)

#include<iostream>
#include<string>
#include<fstream>
#include<stdio.h>
#include<iomanip>
#include<conio.h>
using namespace std;
const int n=100;

class Fly     //航班信息类

public:
   string flyID;//航班班号
   string flyNumber;//飞机编号
   string flycity;//抵达的城市
   string flyUptime;//航班起飞时间
   string flyDowntime;//航班降落时间
   double flyPrice;//票价
   double flyDownPrice;//折扣价格
   int flySeat;//总票数
   int LeaveSeat;//剩余票数
public:
    Fly(string flyID,string flyNumber,string flycity, string flyUptime,string flyDowntime,double flyPrice,double flyDownPrice,int flySeat,int LeaveSeat);
 Fly(){};

    string GetflyID();//返回航班班号
 string GetflyNumber();//返回飞机编号
 string Getflycity();//返回抵达城市
 string GetflyUptime();//返回航班起飞时间
 string GetflyDowntime();//返回航班降落时间
 double GetflyPrice();//返回票价
 double GetflyDown();//返回折扣价格
 int GetflySeat();//返回总票数
 int GetLeaveSeat();//返回剩余票数
   

  
};
Fly::Fly(string flyID,string flyNumber,string flycity, string flyUptime,string flyDowntime,double flyPrice,double flyDownPrice,int flySeat,int LeaveSeat)
{
      this->flyID=flyID;
   this->flyNumber=flyNumber;
   this->flycity=flycity;
   this->flyUptime=flyUptime;
   this->flyDownPrice=flyDownPrice;
   this->flyUptime=flyUptime;
   this->flyDowntime=flyDowntime;
   this->flySeat=flySeat;
   this->LeaveSeat=LeaveSeat;
}

string Fly::GetflyID()
{
   return flyID;
}

string Fly::GetflyNumber()
{
   return flyNumber;
}

string Fly::Getflycity()
{
  return flycity;
}


string Fly::GetflyUptime()
{
 return flyUptime;
}


string Fly::GetflyDowntime()
{
  return flyDowntime;
}


double Fly::GetflyPrice()
{
 return flyPrice;
}


double Fly::GetflyDown()
{
  return flyDownPrice;
}


int Fly::GetflySeat()
{
  return flySeat;
}

int Fly::GetLeaveSeat()
{
  return LeaveSeat;

class FlyBook
{
public:
   Fly data;
   FlyBook *next;
public:
 void init();
 FlyBook *addFly(const Fly &fly);
 void selecttickets(const string flyID);
    void Get(const string &flyID);
    void Booktickets(const string flyID,int sum);
    void refundtickets(const string flyID);
    void correctfly(const string flyID);
 void pass();
    void save();
    void write();
};
FlyBook *head;
Fly fly;
void FlyBook::init()
{
   head=new FlyBook;
   head->next=NULL;

}

FlyBook * FlyBook::addFly(const Fly &fly)         
{
 FlyBook *s;
 s=new FlyBook;
 s->data=fly;
 s->next=head->next;
 head->next=s;
 return head;
}

void FlyBook::selecttickets(const string flyID)             
{
  extern FlyBook *head;
  cout<<"查询结果:"<<endl;
  cout<<endl;
  FlyBook* p;
  p=head->next;
  while(p)
  {
   if(p->data.GetflyID()==flyID)     //从链表中找
   {
   cout<<"飞机编号"<<"/t"<<"航班班号"<<"/t"<<"抵达城市"<<"/t"<<"起飞时间"<<"/t"<<"降落时间"<<endl;
   cout<<p->data.GetflyID()<<"/t/t"<<p->data.GetflyNumber()<<"/t/t"<<p->data.Getflycity()<<"/t/t"<<p->data.GetflyUptime()<<"/t/t"<<p->data.GetflyDowntime()<<endl;
   cout<<"航班票价"<<"/t"<<"票价折扣"<<"/t"<<"总 票 数"<<"/t"<<"剩余票数"<<endl;
   cout<<p->data.GetflyPrice()<<"/t/t"<<p->data.GetflyDown()<<"/t/t"<<p->data.GetflySeat()<<"/t/t"<<p->data.GetLeaveSeat()<<endl;
   cout<<endl;break;
   }
   p=p->next;
  }
  if(p==NULL)
   cout<<"Sorry!无此航班信息"<<endl;
}
void FlyBook::Get(const string &flyID)

   int j=0;
   FlyBook *p;
   p=head->next;
   while(p)
   {
     j++;
  p=p->next;
  if(p->data.GetflyID()==fly.flyID)
  {
    cout<<p->data.GetflyID();
       cout<<p->data.GetflyNumber();
    cout<<p->data.Getflycity();
    cout<<p->data.GetflyUptime();
    cout<<p->data.GetflyDowntime();
    cout<<p->data.GetflyPrice();
          cout<<p->data.GetflyDown();
    cout<<p->data.GetflySeat();
    cout<<p->data.GetLeaveSeat();
  }
  else
   cout<<"该航班票已经处于满的状态"<<endl;
   }

}
void FlyBook::Booktickets(const string flyID,int sum)
{
   FlyBook *p;
   p=head->next;
   while(p)
   {
     
   if(p->data.GetflyID()==flyID)
   {  
    cout<<"显示航班信息"<<endl;
     {
     cout<<p->data.GetflyID();
        cout<<p->data.GetflyNumber();
     cout<<p->data.Getflycity();
     cout<<p->data.GetflyUptime();
     cout<<p->data.GetflyDowntime();
     cout<<p->data.GetflyPrice();
           cout<<p->data.GetflyDown();
     cout<<p->data.GetflySeat();
     cout<<p->data.GetLeaveSeat();
    
      }
   p=p->next;
   }
   else
    cout<<"该航班剩余票数为0"<<endl;
   }
  
}

void FlyBook::refundtickets(const string flyID)
{
   FlyBook *p;
   p=head->next;
   while(p)
   {
  
  if(p->data.GetflyID()==flyID)
  {
   cout<<"显示航班信息"<<endl;
           {
     cout<<p->data.GetflyID();
        cout<<p->data.GetflyNumber();
     cout<<p->data.Getflycity();
     cout<<p->data.GetflyUptime();
     cout<<p->data.GetflyDowntime();
     cout<<p->data.GetflyPrice();
           cout<<p->data.GetflyDown();
     cout<<p->data.GetflySeat();
     cout<<p->data.GetLeaveSeat();
       }
    p=p->next; //cout<<flyBook.loadtickets(3);
  }

   }
}


void FlyBook::correctfly(const string flyID)
{
   FlyBook *p;
   p=head->next;
  while(p->next!=NULL)
 {
  if(p->next->data.GetflyID()==flyID)
  {
   
   Fly fly=p->data;
           
            string flyID;string flyNumber;string flycity;string flyUptime;
            string flyDowntime;double flyPrice;double flyDownPrice;int flySeat;int LeaveSeat;
   cout<<"航班班号"<<endl;
   cin>>flyID;
   cout<<"飞机编号"<<endl;
   cin>>flyNumber;
   cout<<"抵达城市"<<endl;
   cin>>flycity;
   cout<<"航班起飞时间"<<endl;
   cin>>flyUptime;
   cout<<"航班降落时间"<<endl;
   cin>>flyDowntime;
   cout<<"票价"<<endl;
   cin>>flyPrice;
   cout<<"折扣价格"<<endl;
   cin>>flyDownPrice;
   cout<<"总票数"<<endl;
   cin>>flySeat;
   cout<<"剩余票数"<<endl;
   cin>>LeaveSeat;
      Fly newfly(flyID,flyNumber,flycity,flyUptime,flyDowntime,flyPrice,flyDownPrice,flySeat,LeaveSeat);
      fly=newfly;
      p->data=fly;break;
  }
  p=p->next;
    } 

 cout<<"没有找到需要替换的信息.."<<endl;
  
}

//将数据写入到文件中
void FlyBook::save()                                  
{
 ofstream sfile("Fly.txt");
 if(!sfile)
 {
  cerr<<"Fly.txt open failed"<<endl;
  exit(1);
 }
 
 FlyBook *p=head->next;
 while(p)
 {
     sfile<<p->next->data.GetflyID()<<endl;
          cout<<p->data.GetflyNumber()<<endl;
       cout<<p->data.Getflycity()<<endl;
       cout<<p->data.GetflyUptime()<<endl;
       cout<<p->data.GetflyDowntime()<<endl;
       cout<<p->data.GetflyPrice()<<endl;
             cout<<p->data.GetflyDown()<<endl;
       cout<<p->data.GetflySeat()<<endl;
       cout<<p->data.GetLeaveSeat()<<endl;
       p=p->next;
 }
 sfile.close();
}
 
//从文件中读取数据
void FlyBook::write()                                    
{
 FlyBook p;
 ifstream sfile("Fly.txt");
 if(!sfile)
 {
  cerr<<"Fly.txt open failed"<<endl;
  exit(1);
 }

   string flyID;//航班班号
   string flyNumber;//飞机编号
   string flycity;//抵达的城市
   string flyUptime;//航班起飞时间
   string flyDowntime;//航班降落时间
   double flyPrice;//票价
   double flyDownPrice;//折扣价格
   int flySeat;//总票数
   int LeaveSeat;//剩余票数
 while(sfile>>flyID>>flyNumber>>flycity>>flyUptime>>flyDowntime>>flyPrice>>flyDownPrice>>flySeat>>LeaveSeat)
 {  Fly fly(flyID,flyNumber,flycity,flyUptime,flyDowntime,flyPrice,flyDownPrice,flySeat,LeaveSeat);
  p.addFly(fly);
 }
 sfile.close();

}

//需密码登录
void FlyBook::pass()
{
  int t=3;
  char m[6]="1234";
  char password[7]="123456";
     cout<<endl;
  cout<<"/t/t/t    欢迎使用,请进行登陆!"<<endl;
  cout<<endl;
  while(t>0)
  {
   char user[6];
   int c;
   char b[7];
   cout<<"/t/t/t请输入用户名:";
   cin>>user;
   cout<<endl<<"/t/t/t请输入密码:";
   for(int i=0;i<6;i++)
   {
   c=getch();
   b[i]=c;
   cout<<"*";
   }
   b[6]='/0';
   cout<<endl;
   if(strcmp(m,user)!=0||strcmp(password,b)!=0)
   {
    if(t>1)
    {
     cout<<endl<<"/t/t/t用户名或密码输入错误!"<<endl;
     cout<<"/t/t/t"<<"请重新输入!(您还有"<<t-1<<"次机会)"<<endl;
     cout<<endl;
    }
    t--;
   }
   else
    break;
  };
  if(t<=0)
  { 
   cout<<endl;
   cout<<"/t/t/t对不起,请稍候再试 "<<endl;
   cout<<"/t/t/t连续三次输入错误,强制退出程序!"<<endl;
     exit(0);
  }
 }
void main()
{   FlyBook p;
    FlyBook m;
  static int Count=0;
  string User;
  string PassWord;
  p.init();
  p.save();
  string flyID;//航班班号
     string flyNumber;//飞机编号
     string flycity;//抵达的城市
     string flyUptime;//航班起飞时间
     string flyDowntime;//航班降落时间
     double flyPrice;//票价
     double flyDownPrice;//折扣价格
     int flySeat;//总票数
     int LeaveSeat;//剩余票数
     char ch='0';           
 while(User!="11" || PassWord!="22")
 {
  cout<<"/t/t/t  【★★飞机航班登陆系统★★】"<<endl<<endl;
  cout<<"/t/t/t   管理员帐户:";
  cin>>User;
  cout<<endl;
  cout<<"/t/t/t   管理员密码:";
  cin>>PassWord;
  cout<<endl;
  cout<<endl;
  if(User!="11" || PassWord!="22")
  {
   cout<<"密码或帐号不正确,重新输入"<<endl;
   Count++;
   cout<<endl;
  }
  if(Count==3)
  {
     cout<<"您三次输入错误,系统被锁定"<<endl;
     cout<<endl;
     break;
  }
 }
 
 if(User=="11" && PassWord=="22")
 {
  cout<<"/t/t/t   系统正在登陆.请稍候.....";
  //Sleep(2000);
  cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl
   <<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl
   <<endl;
  
   cout<<"/t/t/t  【★★飞机航班系统★★】  "<<endl;
   cout<<endl;
   cout<<"**************************************************"<<endl;
   cout<<"************模拟的航班系统************************"<<endl;
   cout<<"************1.初始化航班信息**********************"<<endl;
   cout<<"************2.增加航班信息************************"<<endl;
   cout<<"************3查询航班信息************************"<<endl;
   cout<<"************4.订票********************************"<<endl;
   cout<<"************5.退票*********************************"<<endl;
   cout<<"************6,修改航班信息************************"<<endl;
   cout<<"************7.退出********************************"<<endl;
   cout<<"请输入1-7";
 }
 while(true)
 {    FlyBook *p;
      p=head->next;
  if(ch=='1')
  { 
   cout<<"初始化航班信息:"<<endl;
      string flyID;//航班班号
            string flyNumber;//飞机编号
            string flycity;//抵达的城市
            string flyUptime;//航班起飞时间
            string flyDowntime;//航班降落时间
            double flyPrice;//票价
            double flyDownPrice;//折扣价格
            int flySeat;//总票数
            int LeaveSeat;//剩余票数
    cout<<"航班班号"<<endl;
   cin>>flyID;
   cout<<"飞机编号"<<endl;
   cin>>flyNumber;
   cout<<"抵达城市"<<endl;
   cin>>flycity;
   cout<<"航班起飞时间"<<endl;
   cin>>flyUptime;
   cout<<"航班降落时间"<<endl;
   cin>>flyDowntime;
   cout<<"票价"<<endl;
   cin>>flyPrice;
   cout<<"折扣价格"<<endl;
   cin>>flyDownPrice;
   cout<<"总票数"<<endl;
   cin>>flySeat;
   cout<<"剩余票数"<<endl;
   cin>>LeaveSeat;
   Fly newfly(flyID,flyNumber,flycity,flyUptime,flyDowntime,flyPrice,flyDownPrice,flySeat,LeaveSeat);
      fly=newfly;
   p->addFly(newfly);
  }
  else if(ch=='2')
  {
     cout<<"增加航班信息:"<<endl;
      string flyID;//航班班号
            string flyNumber;//飞机编号
            string flycity;//抵达的城市
            string flyUptime;//航班起飞时间
            string flyDowntime;//航班降落时间
            double flyPrice;//票价
            double flyDownPrice;//折扣价格
            int flySeat;//总票数
            int LeaveSeat;//剩余票数
   cout<<"航班班号"<<endl;
   cin>>flyID;
   cout<<"飞机编号"<<endl;
   cin>>flyNumber;
   cout<<"抵达城市"<<endl;
   cin>>flycity;
   cout<<"航班起飞时间"<<endl;
   cin>>flyUptime;
   cout<<"航班降落时间"<<endl;
   cin>>flyDowntime;
   cout<<"票价"<<endl;
   cin>>flyPrice;
   cout<<"折扣价格"<<endl;
   cin>>flyDownPrice;
   cout<<"总票数"<<endl;
   cin>>flySeat;
   cout<<"剩余票数"<<endl;
   cin>>LeaveSeat;
   Fly newfly(flyID,flyNumber,flycity,flyUptime,flyDowntime,flyPrice,flyDownPrice,flySeat,LeaveSeat);
   p->addFly(newfly);
   
  }
   else if(ch=='3')
  {
   int i;
   cout<<"* * * * * * * * 查询系统 * * * * * * * *"<<endl;
   cout<<"* * * * * 1.根据航班号进行查找.* * * * *"<<endl;   
   cout<<"* * * * * 3.退出系统        .* * * * * *"<<endl;
   cout<<"输入操作1,3:"<<endl;
   cin>>i;
   if(i==1)
   {
    FlyBook m;
    cout<<"请输入你要查询的航班号:"<<endl;
    string flyID;
    cin>>flyID;
     m.selecttickets(flyID);
    if(fly.GetflyID()!="-1")
    {
     cout<<"航 班 号:"<<fly.GetflyID()<<endl;
     cout<<"飞机编号:"<<fly.GetflyNumber()<<endl;
     cout<<"抵达城市:"<<fly.Getflycity()<<endl;
     cout<<"起飞时间:"<<fly.GetflyUptime()<<endl;
     cout<<"降落时间:"<<fly.GetflyDowntime()<<endl;
     cout<<"航班票价:"<<fly.GetflyPrice()<<endl;
     cout<<"票价折扣:"<<fly.GetflyDown()<<endl;
     cout<<"总 票 数:"<<fly.GetflySeat()<<endl;
     cout<<"剩余票数:"<<fly.GetLeaveSeat()<<endl;
    } 
    else
    cout<<"没有你输入的操作,请退出循环"<<endl;
   }
  }
  else if(ch='4')
  { 
 
  int i;
  cout<<"输入订票系统"<<endl;
        cout<<"* * * * * 1.根据航班号进行查找.* * * * *"<<endl;   
  cout<<"* * * * * 3.退出系统        .* * * * * *"<<endl;
  cin>>i;
  if(i==1)
  {
        FlyBook m;
        cout<<"请输入你要查询的航班号:"<<endl;
        string flyID;
  cin>>flyID;
  
  int sum=0;
  if(fly.GetflyID()==flyID)
  {  
            m.Booktickets(flyID,sum);
      cout<<"输入要定的数量"<<endl;
   cin>>sum;
  }
  }
  else
   cout<<"输出没有操作,请你退出循环"<<endl;
  }
  else if(ch='5')
  {
     int i;
  cout<<"输入退票系统"<<endl;
        cout<<"* * * * * 1.根据航班号进行查找.* * * * *"<<endl;   
     cin>>i;
  if(i==1)
  {
        FlyBook m;
  string flyID;
  cin>>flyID;
  int sum;
  if(fly.GetflyID()==flyID)
  {
    m.refundtickets(flyID);
    cout<<"输入退票数量"<<endl;
          cin>>sum;
  }
  else
          cout<<"输出没有操作,请你退出循环"<<endl;
   }
  }

   else if(ch=='6')
  {  
   
   cout<<"请输入你要修改的航班号:"<<endl;
   string flyID;
   cin>>flyID;
   m.correctfly(flyID);
   if(fly.GetflyID()!="-1")
   {
    cout<<"未修改的航班信息:"<<endl;
    cout<<"航 班 号:"<<fly.GetflyID()<<endl;
    cout<<"飞机编号:"<<fly.GetflyNumber()<<endl;
    cout<<"抵达城市:"<<fly.Getflycity()<<endl;
    cout<<"起飞时间:"<<fly.GetflyUptime()<<endl;
    cout<<"降落时间:"<<fly.GetflyDowntime()<<endl;
    cout<<"航班票价:"<<fly.GetflyPrice()<<endl;
    cout<<"票价折扣:"<<fly.GetflyDown()<<endl;
    cout<<"总 票 数:"<<fly.GetflySeat()<<endl;
    cout<<"剩余票数:"<<fly.GetLeaveSeat()<<endl;

                cout<<"修改后的航班信息"<<endl;
       cout<<"航班班号"<<endl;
       cin>>flyID;
       cout<<"飞机编号"<<endl;
       cin>>flyNumber;
       cout<<"抵达城市"<<endl;
       cin>>flycity;
       cout<<"航班起飞时间"<<endl;
       cin>>flyUptime;
       cout<<"航班降落时间"<<endl;
       cin>>flyDowntime;
       cout<<"票价"<<endl;
       cin>>flyPrice;
       cout<<"折扣价格"<<endl;
       cin>>flyDownPrice;
       cout<<"总票数"<<endl;
       cin>>flySeat;
       cout<<"剩余票数"<<endl;
       cin>>LeaveSeat;
     Fly newfly(flyID,flyNumber,flycity,flyUptime,flyDowntime,flyPrice,flyDownPrice,flySeat,LeaveSeat);
        fly=newfly;
   m.addFly(fly);
   }
  }
      
  else if(ch=='7')
  {
   m.write();
      break;
  }
   cout<<"**************************************************"<<endl;
      cout<<"************模拟的航班系统************************"<<endl;
      cout<<"************1.初始化航班信息**********************"<<endl;
      cout<<"************2.录入航班信息************************"<<endl;
      cout<<"************3查询航班信息************************"<<endl;
      cout<<"************4.订票********************************"<<endl;
      cout<<"************5.退票*********************************"<<endl;
      cout<<"************6,修改航班信息************************"<<endl;
      cout<<"************7.退出********************************"<<endl;
      cout<<"请输入1-7";
  cin>>ch;
  }
 }

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值