Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the plan-landing problem we have discussed in the class where an airpor

ID: 3849744 • Letter: C

Question

Consider the plan-landing problem we have discussed in the class where an airport has one runway and planes request landing. Constraints is that runway request will be granted only if there is a K time gap from either side of the landing request.

For example, suppose K = 3 and a plane request landing time 56. If there are landing requested for 60 and 45 already granted, then the differences from either sides are 60-56 = 4 and 56-45 =11. Satisfies the K=3 constraint. Landing request will be granted. However, if landing times 58 and 45 have already been granted, then 58-56 = 2, which is less than 3. So, landing request will not be granted.

In this problem, you will be implementing several functionalities of this plane landing system using BST (“Landing times BST”). Your plane landing system should first ask for the K value from the user, then implement the following functionalities.

Your landing times BST should store the landing time (use as the key) and the plane flight number in the node.

A) Request landing – input for this functionality is the landing time. You can consider the current time as zero. If the landing time request satisfies the K constraint, grant the landing time and insert the landing time to the landing times BST.

B) Withdraw landing request – A plane can withdraw landing request. This may be due to delay and cancel flight. In this case, remove the landing request from the landing BST.

C) List landing times and the flight number – display the landing times and flights in the

landing times BST.

Write a C or C++ program that Implements above functionality

Explanation / Answer

Program in c++:

#include <iostream>
#include <stdlib.h>
#include <malloc.h>

using namespace std;

typedef struct allFlights{
int landingTimeBST;
string* flightNumber;
allFlights* next;
};

int main() {

cout << "Enter the K value" << std::endl;
int K;
cin >> K;

allFlights *head = NULL;

cout << "Enter option which you want to perform" << endl;
cout << "(R/r) Request Landing" << endl;
cout << "(W/w) Withdraw Landing Request" << endl;
cout << "(L/l) List landing times and flight number" << endl;
cout << "(Q/q) Quit" << endl;

char userOption;

cin >> userOption;

while (true){
if(userOption == 'R' || userOption == 'r'){
if(head == NULL){
head = (allFlights*) malloc(sizeof(allFlights));
cout << "Enter Landing Time BST : ";
cin >> head->landingTimeBST;
if(head->landingTimeBST >= K){
cout << "Enter Flight Number : ";
head->flightNumber = new string;
cin >> *head->flightNumber;
cout << "Done" << endl;
head->next = NULL;
}else{
cout << "Does not satisfies the K constraint" << endl;
free(head);
cout << "Try again" << endl;
}
}else{
allFlights *nextFlight = head;
while (nextFlight->next != NULL){
nextFlight = nextFlight->next;
}
allFlights *newFlight = (allFlights*) malloc(sizeof(allFlights));

cout << "Enter Landing Time BST : ";
cin >> newFlight->landingTimeBST;
bool isInserted = false;


if(head->landingTimeBST - newFlight->landingTimeBST >= K && newFlight->landingTimeBST >= K){

cout << "Enter Flight Number : ";
head->flightNumber = new string;
cin >> *head->flightNumber;
newFlight->next = head;
head = newFlight;
isInserted = true;

}else if(newFlight->landingTimeBST - nextFlight->landingTimeBST >= K){

cout << "Enter Flight Number : ";
head->flightNumber = new string;
cin >> *head->flightNumber;
newFlight->next = NULL;
nextFlight->next = newFlight;
isInserted = true;

}else{

allFlights *prev = head;
nextFlight = head->next;

while (nextFlight != NULL){

if(newFlight->landingTimeBST - prev->landingTimeBST >= K && nextFlight->landingTimeBST - newFlight->landingTimeBST >= K){

cout << "Enter Flight Number : ";
head->flightNumber = new string;
cin >> *head->flightNumber;
prev->next = newFlight;
newFlight->next = nextFlight;
isInserted = true;
break;

}

nextFlight = newFlight->next;
prev = prev->next;

}

if(!isInserted){
cout << "Does not satisfies the K constraint" << endl;
free(newFlight);
cout << "Try again" << endl;
}


}
}
}else if(userOption == 'W' || userOption == 'w'){
allFlights *prevFlight = head;
allFlights *nextFlight = head->next;
cout << "Enter Flight Landing Time BST to Withdraw" << endl;
int landingTimeBST;
cin >> landingTimeBST;

if(head->landingTimeBST == landingTimeBST){
head = head->next;
free(prevFlight);
}else{
bool isWithdrawn = false;
while(nextFlight != NULL){
if(nextFlight->landingTimeBST == landingTimeBST){
prevFlight->next = nextFlight->next;
free(nextFlight);
isWithdrawn = true;
break;

}
prevFlight = prevFlight->next;
nextFlight = nextFlight->next;
}
if(!isWithdrawn){
cout << "Error! Landing Time BST not found" << endl;
cout << "Try again";
}
}

}else if(userOption == 'L' || userOption == 'l'){
allFlights *nextFlight = head;
if(nextFlight == NULL){
cout << "No Flights!" << endl;
} else{
while(nextFlight != NULL){
cout << "Flight Number : " << *nextFlight->flightNumber << " Landing Time BST : " << nextFlight->landingTimeBST << endl;
nextFlight = nextFlight->next;
}
}
}else if(userOption == 'Q' || userOption == 'q'){
break;
}else{
cout << "Wrong input! Please Try again" << endl;
}

cout << "Enter option which you want to perform from above choices" << endl;
cin >> userOption;
}


return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote