C language realizes the flight reservation system

  • 2020-06-23 01:24:45
  • OfStack

The example of this paper shares the specific code of C language to realize flight reservation system for your reference. The specific content is as follows

Description:

Point defines two linked lists, one storing flight information, one storing customer information;

1 series of simple add and delete search;

The following code


#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<<" Please enter flight number, departure time, departure place, arrival time, arrival place, number of seats, number of rows, number of columns, number of seats purchased, number of seats not purchased "<<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'<<" Your location is "<<p->data.r<<" line "<<p->data.c<<" column "<<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'<<" Your flight information is as follows ( The order is flight frequency, departure time, departure place, arrival time, arrival place, total number of seats, seats purchased and seats not purchased )"<<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'<<" Initializes the stored flight information "<<endl;
  cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<" Total number of flights entered :";
  cin>>n;
  system("cls");
  creatp(l,n);
  system("cls");
  while(1)
  {
    cout<<endl;
    cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"1. Customers booking "<<endl;
    cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"2. The customer refund "<<endl;
    cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"3. The customer asks for flight information "<<endl;
    cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"0. Log out "<<endl;
    cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<" Choose function :";
    cin>>choose;
    system("cls");
    if(!choose)
    {
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<endl;
      break;
    }
    else if(choose==1)// booking 
    {
      cout<<endl<<endl;
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<" Flight information is as follows "<<endl;
      show(l);
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<" Enter the customer's name and id number :";
      cin>>k.name>>k.k_id;
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<" Enter the flight number selected by the customer , Position (row, column) :";
      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'<<" The seats are taken and no tickets can be booked , Please reselect !"<<endl;
      }
      getchar();
      getchar();
      system("cls");
    }
    else if(choose==2)// refund 
    {
      cout<<endl<<endl;
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<" Enter customer information ( Name, ID number, flight )"<<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'<<" Refund success "<<endl;
      }
      else
      {
        cout<<endl;
        cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<" The search failed. Please reenter "<<endl;
      }
      getchar();
      getchar();
      system("cls");
    }
    else if(choose==3)
    {
      cout<<endl<<endl;
      cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<" Enter customer information ( Name, ID number, flight ):";
      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'<<" The search failed. Please reenter "<<endl;
      }
      getchar();
      getchar();
      system("cls");
    }
  }
}

For more information, please pay attention to the topic management System Development.


Related articles: