C++

C language flight ticket system C language flight management system


This article shares the specific code of C language flight ticketing system for your reference. The specific content is as follows

Title description: 1 flight ticket system shall be implemented. Each flight shall include the following information: flight number, departure place, destination, total seats, remaining tickets, passenger list, etc. Each passenger’s information is: passenger name, ID number, seat number, etc.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MaxFlight 32  // Maximum number of flights
#define MaxPassenger 1000 // Maximum number of passengers


// Because an array of structs is initialized 4 Information of the number of flights, so the number of flights indication value is 4
char Flight_Num = 4;


// Passenger information
typedef struct
{
  char name[10];// The name
  unsigned int IDnumber;// Id number
  unsigned int seatnumber;// Seat number
}PASSENGER;

// The flight information
typedef struct
{
  char Number[10];// Flight no.
  char Take_off_place[20];// Take off to
  char Destination[20];// destination
  char Take_off_time[10];// Is the departure time
  char Arrive_time[10];// Time of arrival
  unsigned int Totalseats;// The total seats
  unsigned int Leftticket;// The remaining votes
  PASSENGER people[MaxPassenger];
}FLIGHT;


// define 1 An array of structs, initialized first 3 A flight
FLIGHT Fly[MaxFlight]=
  {
 {"PN6620","WuHan","ChongQing","14:10","16:00",1000,1000},
 {"FM1120","ChongQing","ShangHai","13:10","15:50",1000,1000},
 {"FM9364","WuHan","ShangHai","21:40","23:10",1000,1000},
 {"PN6619","ChongQing","WuHan","6:25","8:00",1000,1000}
 };

// Initial menu printing
void menu(void);
// Increase the flight
void Flight_creat(void);
// Delete the flight
void Flight_Delete(void);
// Check the flight number according to the terminal
void Destination_Search(void);
// Check the passenger list by flight number
void Information(void);
// To order tickets
void Flight_book(void);
// Unsubscribe tickets
void Flight_return(void);


int main(void)
{
 char i;

 while(1)
 {
 // First print out the menu
 menu();
 // Then use Switch Statement selection
 scanf("%d",&i);
 switch(i)
 {
  case 1:
  {
  // Increase the flight
  Flight_creat();
  }break;

  case 2:
  {
  // Delete the flight
  Flight_Delete();
  }break;

  case 3:
  {
  // Check the flight number according to the terminal
  Destination_Search();
  }break;

  case 4:
  {
  // Check the passenger list by flight number
  Information();
  }break;

  case 5:
  {
  // To order tickets
  Flight_book();
  }break;

  case 6:
  {
  // Unsubscribe tickets
  Flight_return();
  }break;

  default:;
 }

 }

 return 0;
}

// Initial menu printing
void menu()
{
 printf("------------XXX Aviation management system -------------\n");
 printf("------------1. Increase the flight ------------------\n");
 printf("------------2. Cancellation of flights ------------------\n");
 printf("------------3. Check the flight number according to the terminal ------\n");
 printf("------------4. Check the passenger list by flight number ----\n");
 printf("------------5. To order tickets ------------------\n");
 printf("------------6. Unsubscribe tickets ------------------\n");
 printf("\n What you want to do is: \n");
}

// Increase the flight
void Flight_creat(void)
{
 printf(" Please enter the flight number of the added flight: \n");
 scanf("%s",&Fly[Flight_Num].Number);
 printf(" Please enter the departure point of the additional flight: \n");
 scanf("%s",&Fly[Flight_Num].Take_off_place);
 printf(" Please enter the destination of the added flight: \n");
 scanf("%s",&Fly[Flight_Num].Destination);
 printf(" Please enter the departure time of the additional flight: \n");
 scanf("%s",&Fly[Flight_Num].Take_off_time);
 printf(" Please enter the arrival time of the additional flight: \n");
 scanf("%s",&Fly[Flight_Num].Arrive_time);
 printf(" Please enter the total number of seats: \n");
 scanf("%d",&Fly[Flight_Num].Totalseats);

 // Increase the number of tickets available for flights 1 The fixed number is equal to the total number of seats
 Fly[Flight_Num].Leftticket = Fly[Flight_Num].Totalseats;

 // Finally, add up the total number of flights 1
 Flight_Num++;
}

// Delete the flight
void Flight_Delete(void)
{
 char Flight_name[10];  // A variable used to store the flight number entered
 char i;
 char flag;

 char delete_flag;  // Remove the success flag for subsequent printing of different results

 printf(" Please enter the flight number you want to delete: \n");
 scanf("%s",&Flight_name);

 // The first 1 a for The purpose of the loop is to traverse the entire flight system
 for(i = 0;i < Flight_Num;i++)
 {
   flag = strcmp(Flight_name,Fly[i].Number);
 // Let's say I find the flight
 if(!flag)
 {
  // The first 2 a for The loop is to delete the current flight and the array elements after that flight 1 Time moved forward
  for(;i<Flight_Num;i++)
  {
  Fly[i] = Fly[i+1];
  }

  delete_flag++;

  // Finally, reduce the number of flights 1 , the flight deletion operation is completed, exit the loop
  Flight_Num--;break;
 }
 }

 // Print operation result
 if(delete_flag)
 {
 printf(" Operation successful! The flight number for %s The flight has been deleted! \n",Flight_name);
 }
 else
 {
 printf(" Operation failed! Can't find the flight number %s The flight !",Flight_name);
 }

 delete_flag = 0;

}

// Check the flight number according to the terminal
void Destination_Search(void)
{
 char Flight_Des[20]; // A terminal for storing input
 char i;

 // The query flag is used to determine if the appropriate flight has been found
 char search_flag;
 char flag;

 printf(" Please enter the terminal you want to check: \n");

 scanf("%s",&Flight_Des);

 // Traverse the entire flight system
 for(i = 0;i < Flight_Num;i++)
 {
   flag = strcmp(Flight_Des,Fly[i].Destination);
 if(!flag)
 {
  printf(" Flight information is as follows :\n");
  printf("  The flight number: %s\n",Fly[i].Number);
  printf("  Departure time: %s\n",Fly[i].Take_off_time);
  printf("  Landing time: %s\n",Fly[i].Arrive_time);
  printf("  Remaining votes: %d\n",Fly[i].Leftticket);

  search_flag++;
 }
 }

 if(!search_flag)
 {
 printf(" Sorry, the company has not yet opened flights to the above destinations! \n");
 }

}


// Check the passenger list by flight number
void Information(void)
{
 char Flight_numb[10]; // Used to store incoming flight Numbers
 char i;
 char flag;

 // Used to calculate the number of people booked on a single flight
 unsigned int n;


 printf(" Please enter the flight number you want to check: \n");

 scanf("%s",&Flight_numb);

 // Traverse the entire flight system
 for(i = 0;i < Flight_Num;i++)
 {
   flag = strcmp(Flight_numb,Fly[i].Number);
 if(!flag)
 {
   n = Fly[i].Totalseats - Fly[i].Leftticket;
  // If the flight is booked, that is n Don't for 0 The time, 1 Secondary output passenger name
  if(n)
  {
  printf(" Passenger list: \n");
  for(;n>0;n--)
  {
   printf("%s\n",Fly[i].people[n-1].name);
  }
  }
  else
  {
  printf(" The flight has not been booked yet! \n");
  }break;
 }

 }

}


// To order tickets
void Flight_book(void)
{
 char Flight_numb[10]; // Used to store incoming flight Numbers
 char i;
 char flag;

 // Used to calculate the number of people booked on a single flight
 unsigned int n;

 printf(" Please enter the flight number you want to order: \n");
 scanf("%s",&Flight_numb);

 for(i = 0;i < Flight_Num;i++)
 {
   flag = strcmp(Flight_numb,Fly[i].Number);
 if(!flag)
 {

   n = Fly[i].Totalseats - Fly[i].Leftticket;

  if(Fly[i].Leftticket == 0)
  {
  printf(" There are no tickets left, please make another choice! ");
  break;
  }
  else
  {
  printf(" Please enter your name : \n");
  scanf("%s",&Fly[i].people[n].name);
  printf(" Please enter your ID card number: \n");
  scanf("%d",&Fly[i].people[n].IDnumber);

  // The seat number is not entered by the user
  Fly[i].people[n].seatnumber = n + 1;
  printf(" The booking is successful and the seat number is: %d\n",Fly[i].people[n].seatnumber);
  Fly[i].Leftticket--;
  break;
  }
 }

 }

}
// Unsubscribe tickets
void Flight_return(void)
{
 char Flight_numb[10]; // Used to store incoming flight Numbers
 char i,j;
 unsigned int card_number;  // Used to store the id number entered
 char flag;

 // Used to calculate the number of people booked on a single flight
 unsigned int n;

 unsigned int flag2;

 printf(" Please enter the flight number you want to cancel: \n");
 scanf("%s",&Flight_numb);

 // Traverse the entire flight system
 for(i = 0;i < Flight_Num;i++)
 {
   flag = strcmp(Flight_numb,Fly[i].Number);
 if(!flag)
 {

   n = Fly[i].Totalseats - Fly[i].Leftticket;

  // Go through all the passengers
  printf(" Please enter the id number of the refunder: \n");
  scanf("%d",&card_number);
  for(;n > 0;n--)
  {
    flag2 = card_number - Fly[i].people[n-1].IDnumber;
  if(!flag2)
  {
   for(j=n-1;j < Flight_Num;j++)
   {
   Fly[i].people[j] = Fly[i].people[j+1];
   }
   printf(" Successful refund! \n");
   Fly[i].Leftticket++;
   break;
  }
  }
 }
 }
}

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