Written by Sai Sandeep Thota on March 21, 2013 in C++ > Programming

C++ Program to implement Flight Reservation System

GET ALERTS:

Get our Latest updates delivered to your mailbox!

This is a simple Flight Reservation program using C++. Here we are defining a class called flight and it has two functions. book,availability which are used for booking tickets and other is used for checking availability respectively. We are defining tickets in static because we need to have tickets value to be the same in the whole program. Alternatively we can also initialize tickets in the class by defining it in a function and passing the parameters as we should not initialize a variable in the class. We are setting the tickets value to 80, that means the maximum number of tickets available are 80 in the flight.

book function is used to book the functions, first we need to check the tickets count. The tickets count must be less than or equal to 80 and more than 0. If this condition is met, then we’ll ask the user How many tickets he/she wants. Then we are checking for the tickets available and subtracting the number from total tickets.

availability function is used to print the tickets variable value.

In main function, we are using a switch case to take the user input in order to direct the user appropriately.

Download Source Code

C++ Program to implement Flight Reservation System

#include
#include
#include

class flight {
public:
int n;
static int tickets;
void book();
void availability();
};

int flight::tickets=80;

void flight::book() {
if(tickets<=80&&tickets>0) {

cout<<"\nEnter Number of Tickets:"; cin>>n;
if(tickets>=n) {
tickets=tickets-n;
cout<<"\nYour booking has been confirmed!"; } else { cout<<"\n"<>ch;
switch(ch) {
case 1: ob.book();
break;
case 2: ob.availability();
break;
case 3: exit(1);
default:cout<<"Please enter a valid option!!"; } }while(1); } [/html] Output: flightbooking

You can also customize this program by taking the Passenger information, providing a Confirmation number, Booking tickets in Waiting list etc.,

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: