You are on page 1of 2

// Online C++ compiler to run C++ program online

#include<iostream>
#include<string>
using namespace std;

class flight_booking{
public:

char seat_type;
string meal_type;
int meal_cost;
int seat_cost;
int total_cost;

flight_booking(){
seat_type=' ';
meal_type=' ';
meal_cost=0;
seat_cost=0;
total_cost=0;
} //Default Constructor

flight_booking (char s,string m):seat_type(s), meal_type(m){

find_cost(s);
find_cost(m);

find_total();
} //Constructor Initialization

void find_cost(string meal_type) {


if (meal_type=="Veg") {
meal_cost = 100;
} else {
meal_cost= 200;
}
}

void find_cost(char seat_type){


if (seat_type=='E') {
seat_cost=500;
} else {
seat_cost=2000;
}
}

//Operator Overloading
flight_booking operator+(flight_booking const& obj) {
flight_booking fb;

fb.total_cost = total_cost + obj.total_cost;


return fb;
}

//Function Overloading
void find_total(){
total_cost=meal_cost+seat_cost;

void display(){
cout<<"Seat Choice: "<<seat_type<<"\n";
cout<<"Meal Choice: "<<meal_type<<"\n";
cout<<"Seat Cost: "<<seat_cost<<"\n";
cout<<"Meal Cost: "<<meal_cost<<"\n";
cout<<"Total Cost: "<<total_cost<<"\n";
}
};

int main(){
cout<<"Implementation Of Function Overloading And Operator Overloading\n";

char seat_choice;
string meal_choice;
int i=1,n;
flight_booking total_booking;

cout<<"Enter the number of bookings:";


cin>>n;

while(i<= n) {
cout<<"1. E for Economy\n2. B for Business\n";
cout<<"1. Veg for Veg\n2. Nonveg for Non-Veg\n";

cout<<"Ticket "<<i<<"\n";
cout<<"Choose seat option:";
cin>>seat_choice;
cout<<"Choose meal option:";
cin>>meal_choice;

flight_booking f1(seat_choice,meal_choice);
f1.display();
i++;

total_booking = total_booking+f1;

total_booking.display();
return 0;
}

You might also like