Vehicle Seat Reservation System using C++

Vehicle Seat Reservation System using C++(With Source Code)

Vehicle Seat Reservation System using C++(With Source Code)

Hello, coders. Welcome to the codewithrandom blog. In this article, we will learn how to create a Vehicle Seat Reservation System using C++.

In general, a vehicle reservation system in C++ is a program that allows users to make reservations for different types of vehicles, such as cars, buses, trains, and airplanes by entering the vehicle number. The system keeps track of the availability of vehicles and reserves the selected vehicle for the specified date and time. It therefore shows you the seat you have booked and all the available/empty seats in that vehicle. Here in this project we can make seat reservations for a multiple vehicles by giving each vehicle a unique code.

The system typically consists of a class and functions to represent the users, the reservations, and the interface for interacting with the system. It is a simple model of a Vehicle Seat Reservation System curated using C++ language.

Creating a Casino Game using C++

How does the system work?

The system enables customers to install a new vehicle, reserve seats on current vehicle, check availability, and see vehicle information. Classes are used in the program to record vehicle information such as the vehicle number, driver name, arrival and departure times, origin and destination, and seat availability.

Features of the Vehicle Seat Reservation System:

  • Install a vehicle
  • Reservation
  • Show seats
  • Allotment of a seat
  • Vehicles available
  • Exit from the program

Vehicle Seat Reservation System using C++Source code:

This is a C++ implementation of a vehicle seat reservation system. You can directly use this code by copying it in your IDE to understand the working and then can create it by understanding the project.

#include <conio.h>
#include <cstdio>
#include <iostream>
#include <string.h>
#include <cstdlib>

using namespace std;

static int p = 0;

class a

{

  char busn[5], driver[10], arrival[5], depart[5], from[10], to[10], seat[8][4][10];

public:

  void install();

  void allotment();

  void empty();

  void show();

  void avail();

  void position(int i);

}

bus[10];

void vline(char ch)

{

  for (int i=80;i>0;i--)

  cout<<ch;

}

void a::install()

{

  cout<<"Enter Vehicle no: ";

  cin>>bus[p].busn;

  cout<<"\nEnter Vehicle Driver's name: ";

  cin>>bus[p].driver;

  cout<<"\nVehicle Arrival time: ";

  cin>>bus[p].arrival;

  cout<<"\nVehicle Departure: ";

  cin>>bus[p].depart;

  cout<<"\nFrom: \t\t\t";

  cin>>bus[p].from;

  cout<<"\nTo: \t\t\t";

  cin>>bus[p].to;

  bus[p].empty();

  p++;

}

void a::allotment()

{

  int seat;

  char number[5];

  top:

  cout<<"Vehicle no: ";

  cin>>number;

  int n;

  for(n=0;n<=p;n++)

  {

    if(strcmp(bus[n].busn, number)==0)

    break;

  }

  while(n<=p)

  {

    cout<<"\nSeat Number: ";

    cin>>seat;

    if(seat>32)

    {

      cout<<"\nThere are only 32 seats available in this vehicle.";

    }

    else

    {

    if (strcmp(bus[n].seat[seat/4][(seat%4)-1], "Empty")==0)

      {

        cout<<"Enter passanger's name: ";

        cin>>bus[n].seat[seat/4][(seat%4)-1];

        break;

      }

    else

      cout<<"The seat no. is already reserved.\n";

      }

      }

    if(n>p)

    {

      cout<<"Enter correct Vehicle no.\n";

      goto top;

    }

  }


void a::empty()

{

  for(int i=0; i<8;i++)

  {

    for(int j=0;j<4;j++)

    {

      strcpy(bus[p].seat[i][j], "Empty");

    }

  }

}

void a::show()

{

  int n;

  char number[5];

  cout<<"Enter vehicle no: ";

  cin>>number;

  for(n=0;n<=p;n++)

  {

    if(strcmp(bus[n].busn, number)==0)

    break;

  }

while(n<=p)

{

  vline('*');

  cout<<"Vehicle no: \t"<<bus[n].busn

  <<"\nDriver: \t"<<bus[n].driver<<"\t\tArrival time: \t"

  <<bus[n].arrival<<"\tDeparture time:"<<bus[n].depart

  <<"\nFrom: \t\t"<<bus[n].from<<"\t\tTo: \t\t"<<

  bus[n].to<<"\n";

  vline('*');

  bus[0].position(n);

  int a=1;

  for (int i=0; i<8; i++)

  {

    for(int j=0;j<4;j++)

    {

      a++;

      if(strcmp(bus[n].seat[i][j],"Empty")!=0)

      cout<<"\nThe seat no "<<(a-1)<<" is reserved for "<<bus[n].seat[i][j]<<".";

    }

  }

  break;

  }

  if(n>p)

    cout<<"Enter correct vehicle no: ";

}

void a::position(int l)

{

  int s=0;p=0;

  for (int i =0; i<8;i++)

  {

    cout<<"\n";

    for (int j = 0;j<4; j++)

    {

      s++;

      if(strcmp(bus[l].seat[i][j], "Empty")==0)

        {

          cout.width(5);

          cout.fill(' ');

          cout<<s<<".";

          cout.width(10);

          cout.fill(' ');

          cout<<bus[l].seat[i][j];

          p++;

        }

        else

        {

        cout.width(5);

        cout.fill(' ');

        cout<<s<<".";

        cout.width(10);

        cout.fill(' ');

        cout<<bus[l].seat[i][j];

        }

      }

    }

  cout<<"\n\nThere are "<<p<<" seats empty in Vehicle No: "<<bus[l].busn;

  }

void a::avail()

{


  for(int n=0;n<p;n++)

  {

    vline('*');

    cout<<"Vehicle no: \t"<<bus[n].busn<<"\nDriver: \t"<<bus[n].driver

    <<"\t\tArrival time: \t"<<bus[n].arrival<<"\tDeparture Time: \t"

    <<bus[n].depart<<"\nFrom: \t\t"<<bus[n].from<<"\t\tTo: \t\t\t"

    <<bus[n].to<<"\n";

    vline('*');

    vline('_');

  }

}

int main()

{

system("cls");

int w;

while(1)

{

    //system("cls");

  cout<<"\n\n\n\n\n";

  cout<<"\t\t\t1.Install\n\t\t\t"

  <<"2.Reservation\n\t\t\t"

  <<"3.Show\n\t\t\t"

  <<"4.Vehicles Available. \n\t\t\t"

  <<"5.Exit";

  cout<<"\n\t\t\tEnter your choice:-> ";

  cin>>w;

  switch(w)

  {

    case 1:  bus[p].install();

      break;

    case 2:  bus[p].allotment();

      break;

    case 3:  bus[0].show();

      break;

    case 4:  bus[0].avail();

      break;

    case 5:  exit(0);

  }

}

return 0;

}

Now let us understand the code:-

  • We will start by writing the header of the code with the required libraries – conio.h, cstdio, iostream, string.h, and cstdlib.,
  • Now we will define a static integer variable p = 0; which is used to keep track of the number of installed buses.
  • We will then declare fixed length arrays of char type to store the following information- busn[5], driver[10], arrival[5], depart[5], from[10], to[10], seat[8][4][10];
  • Then we will define a class called “a”, which contains the following member functions – install(), allotment(), empty(), show(), position(), and avail(). We will define these functions outside the class.
  • Now defining the member functions of class outside the class using the scope resolution operator.
  • The install() function asks the user for information about a new bus and add it to the bus array. The following details have to entered upon install() function call –
    Vehicle no., Vehicle Driver’s name, Vehicle Arrival time, Vehicle Departure, From, and To (Destination).
  • The allotment() function enables the user to reserve seats on an already existent bus. It uses a for loop, while loop, if-else-if control statements to define the functionality.
  • The empty() function initializes the seats in a new bus to be “empty”.
  • The show() function displays information of a specific bus, such as the driver, arrival and departure timings From and To, and available seats.
  • The position() function displays a tabular format of the seats on a specific bus and shows which seats are available/empty.
  • The avail() function displays information about all installed buses on the system.
  • Then we will define a vline() function, which is used to output an asterisk-filled horizontal line as you can see in the output attached below.
  • The main() function will display the interface showing all the operations a user can perform in the Vehicle Seat Reservation System. It firstly uses system(“cls”); – Used to clear the screen. It uses a switch case to select between the options – install, allotment, show, avail, exit.
  • This sums up our project of Vehicle Seat Reservation System using C++.

Complaint Management System using C++ (With Source Code)

Final Output:-

Here is an example to show how this project works

Vehicle Seat Reservation System using C++

Choice entered – 1, Installing a vehicle by entering the following details.

Vehicle Seat Reservation System using C++

Choice entered – 2, Making a Reservation.

Vehicle Seat Reservation System using C++

Choice entered – 3, Showing the details, availability of the seats in that particular vehicle.

Vehicle Seat Reservation System using C++

We can add multiple vehicles in this system but as for example we have added only one, here is the output:

Vehicle Seat Reservation System using C++

Conclusion

We have reached the end of this article and have a lot more projects in C++ coming so stay tuned. We have started with awesome and fun projects for you all to understand C++. Learning C++ by creating fun projects makes learning easy and interesting.

Atm Simulator using C++ (With source Code)

If you enjoyed the article and learned something new today, let us know in the comments.

Thank you.

Happy Reading! 🙂

Follow: CodeWithRandom

ADVERTISEMENT



Leave a Reply