C语言实现航班订票系统

 更新时间:2019年12月27日 09:39:33   作者:zoey-lyly  
这篇文章主要为大家详细介绍了C语言实现航班订票系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了C语言实现航班订票系统的具体代码,供大家参考,具体内容如下

描述:

点定义两个链表,一个存储航班信息,一个存储客户信息;

进行一系列简单的增删查找;

代码如下

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
using namespace std;
const int MAXN=250;
typedef struct
{
  string p_id;
  int sum;
  int r;
  int c;
  int selected;
  int select;
  string start;
  string startp;
  string arrive;
  string arrivep;
  int acx[MAXN][MAXN];
} node;
typedef struct Pnode
{
  node data;
  struct Pnode *next;
} Pnode,*Plist;
typedef struct
{
  int r;
  int c;
  string name;
  string kp_id;
  string k_id;
} node1;
typedef struct Knode
{
  node1 data;
  struct Knode *next;
} Knode,*Klist;
void init(Plist &l)
{
  l=new Pnode;
  l->next=NULL;
}
void init(Klist &L)
{
  L=new Knode;
  L->next=NULL;
}
void creatp(Plist &l,int e)
{
  cout<<endl<<endl;
  Plist r=new Pnode;
  r=l;
  for(int i=0; i<e; i++)
  {
    Plist ll=new Pnode;
    cout<<endl;
    cout<<"请依次输入航班班次,起飞时间,起飞地点,到达时间,到达地点,座位行数,列数,总座位数,已被购买的数目,未被购买的数目"<<endl;
    cout<<'\t';
    cin>>ll->data.p_id;
    cout<<" ";
    cin>>ll->data.start;
    cout<<" ";
    cin>>ll->data.startp;
    cout<<" ";
    cin>>ll->data.arrive;
    cout<<" ";
    cin>>ll->data.arrivep;
    cout<<" ";
    cin>>ll->data.r;
    cout<<" ";
    cin>>ll->data.c;
    cout<<" ";
    cin>>ll->data.sum;
    cout<<" ";
    cin>>ll->data.selected;
    cout<<" ";
    cin>>ll->data.select;
    for(int j=1; j<=ll->data.r; j++)
      for(int v=1; v<=l->data.c; v++)
        ll->data.acx[j][v]=0;
    ll->next=NULL;
    r->next=ll;
    r=ll;
  }
}
void creatk(Klist &L,node1 e)
{
  Klist LL=new Knode;
  LL->data=e;
  LL->next=NULL;
  Klist r;
  r=L;
  while(r->next!=NULL)
  {
    r=r->next;
  }
  r->next=LL;
  //cout<<L->next->data.r<<endl;
}
void show(Plist &l)
{
  Plist p=new Pnode;
  p=l->next;
  while(p!=NULL)
  {
    cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<p->data.p_id<<" "<<p->data.start<<" "<<p->data.startp<<" "<<p->data.arrive<<" "<<p->data.arrivep<<" "<<p->data.sum<<" "<<p->data.selected<<" "<<p->data.select<<endl;
    for(int i=1; i<=p->data.r; i++)
    {
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t';
      for(int j=1; j<=p->data.c; j++)
        cout<<p->data.acx[i][j];
      cout<<endl;
    }
    p=p->next;
  }
  return ;
}
void alter(Plist &l,node1 e,int flag)
{
  Pnode *p,*pre;
  p=l->next;
  while(p->data.p_id!=e.kp_id)
  {
    pre=p;
    p=p->next;
  }
  if(flag)
  {
    p->data.select-=1;
    p->data.selected+=1;
    p->data.acx[e.r][e.c]=1;
  }
  else
  {
    p->data.select+=1;
    p->data.selected-=1;
    p->data.acx[e.r][e.c]=0;
  }
  return ;
}
int delet(Klist &L,node1 e)
{
  Klist p,pre;
  p=L;
  while(p->next!=NULL)
  {
    if(p->data.name==e.name&&p->data.k_id==e.k_id&&p->data.kp_id==e.kp_id)
      break;
    pre=p;
    p=p->next;
  }
  if(p==NULL)
    return 0;
  else
  {
    //cout<<"hjdhfjks"<<endl;
    pre->next=p->next;
    free(p);
    return 1;
  }
}
int searchh(Klist &L,node1 e)
{
  Knode *p;
  p=L->next;
  while(p!=NULL)
  {
    if(p->data.name==e.name&&p->data.k_id==e.k_id&&p->data.kp_id==e.kp_id)
    {
      cout<<endl;
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"您的位置是"<<p->data.r<<"行"<<p->data.c<<"列"<<endl;
      return 1;
    }
    p=p->next;
  }
  return 0;
}
void showone(Plist &l,node1 e)
{
  Pnode *p;
  p=l->next;
  while(p!=NULL)
  {
    if(p->data.p_id==e.kp_id)
    {
      cout<<endl;
      cout<<'\t'<<"您的航班信息如下(依次为航班班次,起飞时间,起飞地点,到达时间,到达地点,座位总数,已购座位数,未购座位数)"<<endl;
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<p->data.p_id<<" "<<p->data.start<<" "<<p->data.startp<<" "<<p->data.arrive<<" "<<p->data.arrivep<<" "<<p->data.sum<<" "<<p->data.selected<<" "<<p->data.select<<endl;
      return ;
    }
  }
  return ;
}
int judge(Plist &l,node1 e)
{
  Pnode *p;
  p=l->next;
  while(p!=NULL)
  {
    //cout<<p->data.acx[e.r][e.c]<<endl;
    if(p->data.p_id==e.kp_id)
    {
      if(p->data.acx[e.r][e.c])
        return 0;
    }
    p=p->next;
  }
  return 1;
}
int main()
{
  Plist l;
  Klist L;
  init(l);
  init(L);
  int choose,n;
  node p;
  node1 k;
  cout<<endl<<endl;
  cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"初始化存储航班信息"<<endl;
  cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"输入航班总数:";
  cin>>n;
  system("cls");
  creatp(l,n);
  system("cls");
  while(1)
  {
    cout<<endl;
    cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"1.客户订票"<<endl;
    cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"2.客户退票"<<endl;
    cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"3.客户查询航班信息"<<endl;
    cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"0.退出系统"<<endl;
    cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"选择功能:";
    cin>>choose;
    system("cls");
    if(!choose)
    {
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<endl;
      break;
    }
    else if(choose==1)//订票
    {
      cout<<endl<<endl;
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"航班信息如下"<<endl;
      show(l);
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"输入客户姓名,证件号:";
      cin>>k.name>>k.k_id;
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"输入客户选择的航班号,位置(行,列):";
      cin>>k.kp_id>>k.r>>k.c;
      if(judge(l,k))
      {
        creatk(L,k);
        alter(l,k,1);
      }
      else
      {
        cout<<endl;
        cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"座位已有人,不能订票,请重新选择!"<<endl;
      }
      getchar();
      getchar();
      system("cls");
    }
    else if(choose==2)//退票
    {
      cout<<endl<<endl;
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"输入客户信息(名字,证件号,航班)"<<endl;
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t';
      cin>>k.name>>k.k_id>>k.kp_id;
      int flag=delet(L,k);
      if(flag)
      {
        alter(l,k,0);
        cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"退票成功"<<endl;
      }
      else
      {
        cout<<endl;
        cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"查找失败,请重新输入"<<endl;
      }
      getchar();
      getchar();
      system("cls");
    }
    else if(choose==3)
    {
      cout<<endl<<endl;
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"输入客户信息(名字,证件号,航班):";
      cin>>k.name>>k.k_id>>k.kp_id;
      int flag=searchh(L,k);
      if(flag)
      {
        showone(l,k);
      }
      else
      {
        cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"查找失败,请重新输入"<<endl;
      }
      getchar();
      getchar();
      system("cls");
    }
  }
}

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • 基于Qt实现日志打印系统

    基于Qt实现日志打印系统

    这篇文章主要为大家详细介绍了如何利用Qt开发一个日志打印系统,可以实现打印日志按日期、大小保存,过期删除,窗口实时显示日志,网络传输日志远程调试,需要的可以参考下
    2023-12-12
  • Matlab处理图像后实现简单的人脸检测

    Matlab处理图像后实现简单的人脸检测

    本文主要介绍一下如何使用matlab进行图像处理后实现人脸检测,感兴趣的可以了解一下
    2021-11-11
  • c语言将字符串中的小写字母转换成大写字母

    c语言将字符串中的小写字母转换成大写字母

    本文主要介绍了c语言将字符串中的小写字母转换成大写字母的方法实例。具有很好的参考价值。下面跟着小编一起来看下吧
    2017-04-04
  • C++链表倒序实现方法

    C++链表倒序实现方法

    这篇文章主要介绍了C++链表倒序实现方法,是一个很经典的C++链表操作实例,需要的朋友可以参考下
    2014-08-08
  • C++无法打开源文件bits/stdc++.h的问题

    C++无法打开源文件bits/stdc++.h的问题

    这篇文章主要介绍了C++无法打开源文件bits/stdc++.h的问题以及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2023-08-08
  • C语言编写简单的定时关机程序

    C语言编写简单的定时关机程序

    本文给大家分享的是一则C语言编写的简单的定时关机程序,可以设置0-600秒倒计时,有需要的小伙伴可以参考下。
    2016-02-02
  • 详解C++编程中的条件判断语句if-else与switch的用法

    详解C++编程中的条件判断语句if-else与switch的用法

    这篇文章主要介绍了C++编程中的条件判断语句if-else与switch的用法,是C++入门学习中的基础知识,需要的朋友可以参考下
    2016-01-01
  • Matlab绘制花里胡哨的山脊图

    Matlab绘制花里胡哨的山脊图

    这篇文章主要介绍了如何利用Matlab实现绘制一些花里胡哨的山脊图,文中的示例代码讲解详细,对我们学习Matlab有一定的帮助,需要的可以参考一下
    2023-02-02
  • C语言三种函数调用约定_cdecl与_stdcall及_fastcall详细讲解

    C语言三种函数调用约定_cdecl与_stdcall及_fastcall详细讲解

    本篇文章使用的工具是vs2010,内容可能涉及到汇编的知识,建议有一些汇编基础的再来看,不过没有汇编基础也没有关系,了解一下这三种调用约定即可
    2022-10-10
  • C++版图书管理系统

    C++版图书管理系统

    这篇文章主要为大家详细介绍了C++版图书管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-03-03

最新评论