Home » Code Snippets » C/C++ Code Snippets

C++ program for flight booking system



This program is asked by Syed AMir Ali Jaffary through comment on 22/11/2016.

Question

Hey I need your help please, how can we solve this whole program in arrays in dev c++??? (1. ABC airlines have started its operations in November 2015. Currently operating in 5 locations and a single flight per day on a route. Do ask the user to give the origin and destination and date of travel. Display the fare (set the fare for all routes) along with 19% Tax. )

Answer

In this program we are creating a flight booking system by store 5 flight routes with fares and total fares including 19% tax.

Array variables which are using in this program are:

  • route - this will store source to destination route
  • fare - this will store fare against defined route
  • totalFare - this will store total fare (fare + 19% tax on fare)

Use define functions which are using in this program:

void setRoute(char *path[], float *fare, float *tfare)

This function will store the flight routes of 5 locations along with fare and total fare including 19% tax.

void displayPath(char *path[],float *fare, float *tfare)

This function will display the stored fligh routes along with fare and total fare including 19% tax while booking the ticket.

Flight booking system program in C++

#include <iostream>

using namespace std;

void setRoute(char *path[], float *fare, float *tfare){
	int i=0;
	for(i=0;i<5;i++){
		cout<<"Enter flight route:"<<endl;
		cout<<"Route ["<<i+1<<"] : ";
		path[i]=new char[100];
	    cin.ignore(1);
		cin.getline(path[i],100);
		cout<<"Enter fare: ";
		cin>>fare[i];
		tfare[i]=fare[i]+(fare[i]*19/100);
	}
}

void displayPath(char *path[],float *fare, float *tfare){
	int i=0;
	cout<<"Available flight routes are:"<<endl;
	for(i=0;i<5;i++){
		cout<<"Route ["<<i+1<<"] : "<<path[i]
		<<" - Fare: "<<fare[i]<<",Total Fare: "<<tfare[i]<<endl;
	}	
}


int main(){
	//variable to store flight route 
	char *route[5];
	float fare[5],totalFare[5];
	char name[30],path[100];
	int d,m,y;
	int routeId;
	
	setRoute(route,fare,totalFare);
	
	cout<<endl<<endl;
	cout<<"Enter name: ";
	cin.ignore(1);
	cin.getline(name,30);
	
	cout<<"Enter date of travel (d m y): ";
	cin>>d>>m>>y;
	
	displayPath(route,fare,totalFare);
	cout<<"Choose flight route (1 to 5): ";
	cin>>routeId;
	
	if(routeId<1 || routeId>5){
		cout<<"Invalid flight route!!!"<<endl;
		return 0;
	}
	
	cout<<endl<<endl;
	cout<<"Congratulations... "<<name<<" your ticket has been booked."<<endl;
	cout<<"Travel date is: "<<d<<"/"<<m<<"/"<<y<<endl;
	cout<<"Flight route: "<<route[routeId-1]<<endl;
	cout<<"Total fare is: "<<totalFare[routeId-1]<<endl;
	
	return 0;
}

Output

Enter flight route: 
Route [1] : DELHI TO GOA
Enter fare: 1000
Enter flight route: 
Route [2] : DELHI TO MUMBAI 
Enter fare: 2000
Enter flight route: 
Route [3] : DELHI TO AGRA 
Enter fare: 1500
Enter flight route: 
Route [4] : GOA TO MUMBAI 
Enter fare: 2500
Enter flight route: 
Route [5] : MUMBAI TO GOA 
Enter fare: 3500

Enter name: PANKAJ SINGH
Enter date of travel (d m y): 22 11 2016
Available flight routes are:
Route [1] : ELHI TO GOA - Fare: 1000,Total Fare: 1190 
Route [2] : DELHI TO MUMBAI - Fare: 2000,Total Fare: 2380 
Route [3] : DELHI TO AGRA - Fare: 1500,Total Fare: 1785 
Route [4] : GOA TO MUMBAI - Fare: 2500,Total Fare: 2975 
Route [5] : MUMBAI TO GOA - Fare: 3500,Total Fare: 4165 
Choose flight route (1 to 5): 3 


Congratulations... PANKAJ SINGH your ticket has been booked.
Travel date is: 22/11/2016
Flight route: DELHI TO AGRA 
Total fare is: 1785 

Try to make this program through class and object and store flight routes into the file by yourself.






Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.