Create an Airline Booking System Using C with Free Codes

Table of Contents

Introduction – Airline Booking System

Hello Guys, Here we are going to create an Airline Booking System using C Language. In the Project, the User can Book, Cancel, and also see the Booking Data. This tinny project does have not any Login/Signup System. But the features of This project are the cool and enough for your college-level project help.

Feature of this Project

Here is the List of the Features which is provided in this project,

  1. Reservation
  2. Cancel Booking
  3. Display Record

Software Used for Run Project

Here we used Code::Blocks for Run the Airline Booking System Project Code File. Because this project is console based project and the Code::Blocks is the Beginner Console Friendly software.

C Language Free E-Book

Output – Airline Booking System

Explanation about Project

Here we explain the Airline Booking System,

Part – 1 Header File

Here we include several standards C Libraries,

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<Windows.h>
  • “stdio.h” is the Standard Input/Output Operations.
  • “stdlib.h” is standard Library for general utilities.
  • “conio.h” is console Input/Output Functions.
  • “string.h” is String handling function.
  • “Windows.h” is a Windows Specific Function.

Part – 2 Data Structure

struct mufti_airline
{
    char passport[6];
    char name[15];
    char destination[15];
    int seat_num;
    char email[15];
    struct mufti_airline *following;
};

Here we define the “mufti_airline” which is used for representing passenger details for flight. It includes fields for passport number, name, destination, seat number, email, and a pointer to the next node.

Part – 3 Global Variables

struct mufti_airline *begin, *stream, *dummy;

Here we write the Global Pointers to track the beginning of the linked list (“begin”), the current node (“stream”), and a temporary node from deletion (“dummy”).

C Language Free Notes

Part – 4 Function Prototype

void reserve(int x), cancel(), display(), savefile();

Prototype for functions used in the program.

Part – 5 Main Function

void main()

It is the entry point of the program. And Displays the menu for reservation, cancellation, displaying records, or exiting the program. It reads user input and calls corresponding functions based on the choice.

Part – 6 Reserve Function

void reserve(int x)
{
    stream = begin;
    if (begin == NULL)
    {
        // first user
        begin = stream = (struct mufti_airline*)malloc(sizeof(struct mufti_airline));
        details();
        stream->following = NULL;
        printf("\n\t Seat booking successful!");
        printf("\n\t your seat number is: Seat A-%d", x);
        stream->seat_num = x;
        return;
    }
    else if (x > 15) // FULL SEATS
    {
        printf("\n\t\t Seat Full.");
        return;
    }
    else
    {
        // next user
        while (stream->following)
            stream = stream->following;
        stream->following = (struct mufti_airline *)malloc(sizeof(struct mufti_airline));
        stream = stream->following;
        details();
        stream->following = NULL;
        printf("\n\t Seat booking succesful!");
        printf("\n\t your seat number is: Seat A-%d", x);
        stream->seat_num = x;
        return;
    }
}

In the we accepts a seat number (‘x’) and reserve a seat for a passenger. If it’s the first reservation, it creates the initial node and assign details to it. If not, it traverses to he end of the linked list and adds a new node with passenger details.

Play Quiz Gain Knowledge

Part – 7 Details Function

void details()
{
    printf("\n\t Enter your passport number:");
    gets(stream->passport); fflush(stdin);   //reads a line from stdin and stores it into the string pointed
    printf("\n\t Enter your  name:");
    gets(stream->name); fflush(stdin);
    printf("\n\t Enter your email address:");
    gets(stream->email); fflush(stdin);
    printf("\n\t Enter the Destination : ");
    gets(stream->destination); fflush(stdin);
}

Prompts the user to enter passport number, name, email, and destination. Stores the entered details into the current ‘stream’.

Part – 8 Savefile Function

void savefile()
{
    FILE *fpointer = fopen("mufti records", "w");
    if (!fpointer)
    {
        printf("\n Error in opening file!");
        return;
        Sleep(800);
    }
    stream = begin;
    while (stream)
    {
        fprintf(fpointer, "%-6s", stream->passport);
        fprintf(fpointer, "%-15s", stream->name);
        fprintf(fpointer, "%-15s", stream->email);
        fprintf(fpointer, "%-15s", stream->destination);
        fprintf(fpointer, "\n");
        stream = stream->following;
    }
    printf("\n\n\t Details have been saved to a file (mufti records)");
    fclose(fpointer);
}

This Function is used for writes passenger details to a file named “mufti records”. It iterates through the linked lists and writes each node’s details to the file.

Part – 9 Display Function

void display()
{
    stream = begin;
    while (stream)
    {
        printf("\n\n Passport Number : %-6s", stream->passport);
        printf("\n         name : %-15s", stream->name);
        printf("\n      email address: %-15s", stream->email);
        printf("\n      Seat number: A-%d", stream->seat_num);
        printf("\n     Destination:%-15s", stream->destination);
        printf("\n\n++*=====================================================*++");
        stream = stream->following;
    }

}

This Function is used for display all the passenger details which is stored in linked lists. It iterates through the linked lists and prints each node’s details.

Part – 10 Cancel Function

void cancel()
{
    stream = begin;
    system("cls");
    char passport[6];
    printf("\n\n Enter passort number to delete record?:");
    gets(passport); fflush(stdin);
    if (strcmp(begin->passport, passport) == 0)
    {
        dummy = begin;
        begin = begin->following;
        free(dummy);
        printf(" booking has been deleted");
        Sleep(800);
        return;

    }

This Function is used for cancels the reservation based on the provided passport number. This Prompts the user will enter the passport number. If the passport number matches the first node, it deletes that node. Otherwise, it traverses the list and deletes the node with the matching passpost number.

Complete Project Codes

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


struct mufti_airline
{
    char passport[6];
    char name[15];
    char destination[15];
    int seat_num;
    char email[15];
    struct mufti_airline *following;
}
*begin, *stream;
struct mufti_airline *dummy;


void main()
{
    void reserve(int x), cancel(), display(), savefile();  //function prototypes
    int choice;
    begin = stream = NULL;  //initialize the struct pointers to NULL
    int num = 1;
    do
    {

        printf("\n\n\t\t ********************************************************************");
        printf("\n\t\t                   welcome to Sharath's airline system                   ");
        printf("\n\t\t   *******************************************************************");
        printf("\n\n\n\t\t Please enter your choice from below (1-4):");
        printf("\n\n\t\t 1. Reservation");
        printf("\n\n\t\t 2. Cancel");
        printf("\n\n\t\t 3. DISPLAY RECORDS");
        printf("\n\n\t\t 4. EXIT");
        printf("\n\n\t\t feel free to contact ");
        printf("\n\n\t\t Enter your choice :");



        scanf("%d", &choice); fflush(stdin);
        system("cls");
        switch (choice)
        {
        case 1:
            reserve(num);
            num++;
            break;
        case 2:
            cancel();
            break;
        case 3:
            display();
            break;
        case 4:
        {
                  savefile();
                  break;
        }
        default:
            printf("\n\n\t SORRY INVALID CHOICE!");
            printf("\n\n\t PLEASE CHOOSE FROM 1-4");
            printf("\n\n\t Do not forget to chose from 1-4");
        }
        getch();
    } while (choice != 4);
}
// ************************GOOD LUCK MUFTI*****************************
void details()
{
    printf("\n\t Enter your passport number:");
    gets(stream->passport); fflush(stdin);   //reads a line from stdin and stores it into the string pointed
    printf("\n\t Enter your  name:");
    gets(stream->name); fflush(stdin);
    printf("\n\t Enter your email address:");
    gets(stream->email); fflush(stdin);
    printf("\n\t Enter the Destination : ");
    gets(stream->destination); fflush(stdin);
}


// ************************************GOOD LUCK MUFTI************************************
void details();

void reserve(int x)
{
    stream = begin;
    if (begin == NULL)
    {
        // first user
        begin = stream = (struct mufti_airline*)malloc(sizeof(struct mufti_airline));
        details();
        stream->following = NULL;
        printf("\n\t Seat booking successful!");
        printf("\n\t your seat number is: Seat A-%d", x);
        stream->seat_num = x;
        return;
    }
    else if (x > 15) // FULL SEATS
    {
        printf("\n\t\t Seat Full.");
        return;
    }
    else
    {
        // next user
        while (stream->following)
            stream = stream->following;
        stream->following = (struct mufti_airline *)malloc(sizeof(struct mufti_airline));
        stream = stream->following;
        details();
        stream->following = NULL;
        printf("\n\t Seat booking succesful!");
        printf("\n\t your seat number is: Seat A-%d", x);
        stream->seat_num = x;
        return;
    }
}
// ************************GOOD LUCK MUFTI********************************


void savefile()
{
    FILE *fpointer = fopen("mufti records", "w");
    if (!fpointer)
    {
        printf("\n Error in opening file!");
        return;
        Sleep(800);
    }
    stream = begin;
    while (stream)
    {
        fprintf(fpointer, "%-6s", stream->passport);
        fprintf(fpointer, "%-15s", stream->name);
        fprintf(fpointer, "%-15s", stream->email);
        fprintf(fpointer, "%-15s", stream->destination);
        fprintf(fpointer, "\n");
        stream = stream->following;
    }
    printf("\n\n\t Details have been saved to a file (mufti records)");
    fclose(fpointer);
}
//********************************GOOD LUCK MUFTI***************************************

void display()
{
    stream = begin;
    while (stream)
    {
        printf("\n\n Passport Number : %-6s", stream->passport);
        printf("\n         name : %-15s", stream->name);
        printf("\n      email address: %-15s", stream->email);
        printf("\n      Seat number: A-%d", stream->seat_num);
        printf("\n     Destination:%-15s", stream->destination);
        printf("\n\n++*=====================================================*++");
        stream = stream->following;
    }

}
//*****************************GOOD LUCK MUFTI*************************************

void cancel()
{
    stream = begin;
    system("cls");
    char passport[6];
    printf("\n\n Enter passort number to delete record?:");
    gets(passport); fflush(stdin);
    if (strcmp(begin->passport, passport) == 0)
    {
        dummy = begin;
        begin = begin->following;
        free(dummy);
        printf(" booking has been deleted");
        Sleep(800);
        return;

    }

    while (stream->following)
    {
        if (strcmp(stream->following->passport, passport) == 0)
        {
            dummy = stream->following;
            stream->following = stream->following->following;
            free(dummy);
            printf("has been deleted ");
            getch();
            Sleep(800);
            return;
        }
        stream = stream->following;
    }
    printf("passport number is wrong please check your passport");

}

Conclusion – Airline booking System

Here we learn about how we create an Airline Booking System by the use of C Language. How the flow of program works, and how the functions works which is used for take user input and display user input functions.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top