(Airline Reservations System) A small airline has just purchased a computer for
ID: 675274 • Letter: #
Question
(Airline Reservations System) A small airline has just purchased a computer for its new automated reservations system. You’ve been asked to develop the new system. You are to write an application to assign seats on each flight of the airline’s only plane (capacity: 10 seats).
Your application should display the following alternatives: Please type 1 for First Class and Please type 2 for Economy. If the user types 1, your application should assign a seat in the firstclass section (seats 1–5). If the user types 2, your application should assign a seat in the economy section (seats 6–10). Your application should then display a boarding pass indicating the person’s seat number and whether it’s in the first-class or economy section of the plane.
Use a one-dimensional array of primitive type boolean to represent the seating chart of the plane. Initialize all the elements of the array to false to indicate that all the seats are empty. As each seat is assigned, set the corresponding element of the array to true to indicate that the seat is no longer available.
Your application should never assign a seat that has already been assigned. When the economy section is full, your application should ask the person if it’s acceptable to be placed in the first-class section (and vice versa). If yes, make the appropriate seat assignment. If no, display the message "Next flight leaves in 3 hours."
Please solve in VISUAL BASIC
Explanation / Answer
Answer :
#include <iostream>
using namespace std;
bool availability_checking_seat(int);
int choice_select();
void next_flight_availability();
void reserve_boarding_flight(int);
int capacity[10] = {0};
int main()
{
int option;
bool availability = false;
bool availability_other = false;
for(int x = 0; x < 12; x++)
{
// choice select
option = choice_select();
// check seats availibility in selected section for seats
availability = availability_checking_seat(option);
if(availability == 1)
{
// if there is available place print boarding pass for flights
reserve_boarding_flight(option);
}
else
// if there is no available place, check seats availability in other section
{
if(option == 1)
availability_other = availability_checking_seat(2);
else
availability_other = availability_checking_seat(1);
}
if(availability == 0 && availability_other == 1)
{
cout << "There is available place in another section "
<< " Do you want to buy it? (yes->type y, no->type n)" << endl;
char other_section;
cin >> other_section;
while(other_section != 'y' && other_section != 'n')
{
cout << "Please enter correct answer option" << endl;
cin >> other_section;
}
if(other_section == 'n')
next_flight_availability();
else
if(option == 1)
reserve_boarding_flight(2);
else
reserve_boarding_flight(1);
}
// if there is no available place in other section display message on screen
else if(availability == 0 && availability_other == 0)
next_flight_availability();
}
}
// display message and choice to select
int choice_select()
{
int class_option;
cout << "Please type 1 for "First Class""
<< " Please type 2 for "Economy"" << endl;
cin >> class_option;
while(class_option != 1 && class_option != 2)
{
cout << "Please enter correct choice!" << endl;
cout << "Please type 1 for "First Class""
<< " Please type 2 for "Economy"" << endl;
cin >> class_option;
}
return class_option;
}
// seats availability in flight
bool availability_checking_seat(int opt)
{
int counter_a = 0;
int counter_b = 0;
if(opt == 1)
{
for(int i = 0; i < 5; i++)
{
if(capacity[i] == 0)
counter_a++;
}
}
else
{
for(int j = 5; j < 10; j++)
{
if(capacity[j] == 0)
counter_b++;
}
}
if((opt == 1 && counter_a > 0) || (opt == 2 && counter_b > 0))
{
cout << "There is available place in section " << endl;
return 1;
}
else
{
cout << "There is no available place in section " << endl;
return 0;
}
}
// display text about next flight
void next_flight_availability(void)
{
cout << "Next flight leaves in 3 hours." << endl;
}
// reserve seat and print boarding pass
void reserve_boarding_flight(int section)
{
int seat = 0;
if(section == 1)
{
for(int i = 0; i < 5; i++)
{
if(capacity[i] == 0)
{
capacity[i] = 1;
seat = i + 1;
}
if(seat != 0)
break;
}
if(seat != 0)
{
cout << "**** 1. Boarding Pass **** Your section: " << section
<< " Your seat: " << seat << endl;
}
}
else
{
for(int j = 5; j < 10; j++)
{
if(capacity[j] == 0)
{
capacity[j] = 1;
seat = j + 1;
}
if(seat != 0)
break;
}
if(seat != 0)
{
cout << "**** 2. Boarding Pass **** Your section: " << section
<< " Your seat: " << seat << endl;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.