Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add file handling in the following C++ code, The code should store the data entered by use in .txt file: #include using namespace std; int

Add file handling in the following C++ code, The code should store the data entered by use in .txt file:

#include

using namespace std;

int seat_select(int seats[]);

void meal(bool opt);

void wifi(bool opt);

int main()

{

int seats[20], i, count=0, eco=5;

bool res;

cout<<"\t|Airline Reservation System|"<

cout<<"We have 9 First class tickets and 11 Economy Class tickets."<

seat_select(seats);

return 0;

}

int seat_select(int seats[])

{

int i, count=0, eco=9;

bool opt,choice;

for ( i=1 ; i<=20 ; i++)

{

label: cout<<"Press 1 for First Class Press 2 for Economy Press 3 to exit."<

cin>>seats[i];

if (seats[i]==1)

{

cout<<"You selected First Class."<

count++;

while(count<10)

{

cout<<"\t********Boarding Pass******** \tYour ticket has been reserved in First Class \tYour seat number = "<

cout<<"Do you want to add a Meal?(Press 1 to accept and 0 to deny): ";

cin>>opt;

meal(opt);

cout<

cout<<"Do you want to add Wi-Fi Connection Service?(Press 1 to accept and 0 to deny): ";

cin>>choice;

wifi(choice);

cout<

goto label;

}

if (count>9)

{

cout<<"Sorry all the tickets in First Class have been booked.."<

cout<<"You want a ticket in economy? If yes then select Economy!! "<

goto label;

}

}

else if (seats[i]==2)

{

cout<<"You selected economy. "<

eco++;

while (eco<21)

{

cout<<"\t********Boarding Pass******** \tYour ticket has been reserved in Economy. \tYour seat number "<

cout<<"Do you want to add a Meal?(Press 1 to accept and 0 to deny): ";

cin>>opt;

meal(opt);

cout<

cout<<"Do you want to add Wi-Fi Connection Service?(Press 1 to accept and 0 to deny): ";

cin>>choice;

wifi(choice);

cout<

goto label;

}

if (eco>20)

{

cout<<"Sorry Economy is Full."<

cout<<"You want a ticket in First Class? If yes then select First Class!! "<

goto label;

}

}

else {

cout<<"RESERVATION ENDED!";

return 0;

}

}

}

void meal(bool opt)

{

int choice,charge;

if (opt==1)

{

cout<<"Press 1 for First Class Meal Press 2 for Economy Meal Press 3 fror Standard Meal."<

cout<<"(*Additional charges may apply*)"<

cin>>choice;

switch(choice)

{

case 1:

cout<<" You have added First-Class meal which consists of Rice, Gravy, Tortilla, Salad, Fruit Riffle in Desserts, Water and Soft-Drink at additional cost $25. "<

break;

case 2:

cout<<" You have added Economy meal which consists of Rice, Gravy, Salad, Water and Soft-Drink at additional cost $15."<

break;

case 3:

cout<<"You have added Standard meal which consists of Rice, Salad and Water at additional cost of $5."<

break;

default:

break;

}

}

}

void wifi(bool opt)

{

if(opt==1)

{

cout<<"You have added WiFi Connection Service at additional cost of $20 Per-Hour."<

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions