The Banana Republic Airways (BRA) has just purchased a computer for its new auto
ID: 3724556 • Letter: T
Question
The Banana Republic Airways (BRA) has just purchased a computer for its new automated reservation system. The company has flights from izmir to six other cities in Turkey. The cities are referred to by number, 1 to 6. The prices for one-way flight ticket to each city are as follows: City Code1 4 6 Price(TL) 45 45 75 35 65 Each flight has a boarding capacity of 15 seats; they are numbered from 1 to 15. You are supposed to write a program that processes the order of each customer. The program should get the name of the passenger, the code of the destination city, and the number of tickets desired with a maximum of 5 tickets per sale If the passenger's order is completely satisfied, the program let the user choose the seat numbers from the displayed list of free seats in that flight and display the cost, otherwise continues with the next passenger by displaying an appropriate message You will design your test cases for 10 passenger's orders such that the code (a value between 1 and 6) and number of ticket (a value between 1 and 5) are generated randomly. You should only enter the name of the passenger, (that you design your code to choose from list of 10 names though). Do not forget to display random values in the output for each case Finally, after having processed 10 orders and the program should display the total number tickets sold to each of the six cities as well as the name of the passenger with their seat numbers in that flight and the grand total of all the ticket prices. For simplicity assume that one passenger that requires more than one ticket will use the same name his/her ticketsExplanation / Answer
Please find the code below to get the answer
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
prog.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
using namespace std;
class Passenger {
public :
string pass_name;
int total_tickets;
int dest_city_code;
int total_price;
int selectedSeats[15];
};
class city{
int cityCode ;
int ticketsSold;
int avaiableSeats[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int selectedSeats[15];
};
void deleteseatfromAvailable(int arr[], int size,int del){
for(int i=0; i<size; i++)
{
if(arr[i]==del)
{
for(int j=i; j<(size-1); j++)
{
arr[j]=arr[j+1];
}
break;
}
}
}
void processTicket(){
city c1,c2,c3,c4,c5,c6;
char satisfiedYesNo;
char NextBooking = 'Y';
int City[][15] = {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
} ;
int selectedCity[6][15];
//City Code 1 2 3 4 5 6
const int city_code[6] = {1,2,3,4,5,6};
int overalltickets,overallprice = 0;
//Price(TL) 55 45 45 75 35 65
const int price[6] = {55,45,45,75,35,65};
// Each flight has a boarding capacity of 15 seats; they are numbered from 1 to 15.
const int maxCapacity = 15;
int Dest_City = 7,Number_of_tickets = 6,total_price = 0;
string passenger_name;
//You are supposed to write a program that processes the order of each customer.
while(NextBooking == 'Y'){
Passenger pass;
//The program should get the name of the passenger
cout<<"Enter the name of passenger : ";
cin>>pass.pass_name;
//the code of the destination city,
while(Dest_City >=6){
cout<<"Enter the destination city code (1 - 6)";
cin>>Dest_City;
pass.dest_city_code =Dest_City;
if(Dest_City<=0){
Dest_City = 7;
}
}
//and the number of tickets desired with a maximum of 5 tickets per sale.
while(Number_of_tickets >=5){
cout<<"Please enter the number of tickets ( maximum 5)";
cin>>Number_of_tickets;
if(Number_of_tickets< 0){
Number_of_tickets = 6;
}
pass.total_tickets = Number_of_tickets;
}
//{55,45,45,75,35,65}
switch(Dest_City) {
case 1 :
total_price = Number_of_tickets * price[0];
break;
case 2 :
total_price = Number_of_tickets * price[1];
break;
case 3 :
total_price = Number_of_tickets * price[2];
break;
case 4 :
total_price = Number_of_tickets * price[3];
break;
case 5 :
total_price = Number_of_tickets * price[4];
break;
case 6 :
total_price = Number_of_tickets * price[5];
break;
default :
cout << "Invalid city" << endl;
}
pass.total_price = total_price;
overallprice +=total_price;
overalltickets += Number_of_tickets;
//If the passenger’s order is completely satisfied,
cout<<"Are you satisfied with the purchase (Y / N ) :";
cin>>satisfiedYesNo;
//the program let the user choose the seat numbers from the displayed list of free seats in that flight and display the cost,
if(satisfiedYesNo == 'Y' || satisfiedYesNo == 'y'){
cout<< "Please select the seat numbers from the list : "<<endl;
for(int i=0;i<15;i++)
{
cout<<i<<" ";
}
for(int i =0;i<Number_of_tickets;i++){
cout<<"Enter the "<<i+1<<" seat :";
cin>>selectedCity[Dest_City][i];
deleteseatfromAvailable(City[Dest_City],15,selectedCity[Dest_City][i]);
}
cout<<"You have selected the seats : ";
for(int i =0;i<Number_of_tickets;i++){
cout<<selectedCity[Dest_City][i]<<" ";
//pass.selectedSeats = City[Dest_City][i];
}
cout<<endl<<"The total cost of ticket is : "<<total_price<<endl;
}
//otherwise continues with the next passenger by displaying an appropriate message.
cout<<"Your booking has been done..Do you wish to book for another passenger (Y / N) :";
cin>>NextBooking;
}
cout<<"The total price is : "<<overallprice;
cout<<"the total number of ticket sold : "<< overalltickets;
}
int getCityCode(){
return rand() % 6 + 1;
}
int getTicket(){
return rand() % 5 + 1;
}
int main()
{
processTicket();
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Happy Coding
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.