Plane landing is an optimization problem and need sophisticated
algorithms to assign landing time and runway to each plane. You have to develop a very simplistic
solution to the plane landing problem. Here is the assumption for the problem that you are going to
solve:
Input to the program is a schedule of flights who are going to land in 10 minutes. For each flight you will
have to enter some following information: flight number, remaining fly time (this time is updated when it
contacts the AirController), scheduled landing time (this time of all the flights have to be within this 10
minute window). Sample data might look like this:
Arrival Time From Flight No.
Airport for which we are designing this solution has only three runways. Each runway can be used for
landing. Once a plane is allocated to a runway it will be occupied for at least 2 minutes.
#include <iostream>
using namespace std;
class Time{
int hours, minutes;
public:
Time(): hours(23), minutes(59){}
Time(int h, int m): hours(h), minutes(m){}
void display(){
cout<<hours<<":";
if(minutes < 10) cout<<0;
cout<<minutes;
}
bool operator<(const Time &t){
if(this->hours < t.hours) return true;
else if(this->minutes < t.minutes) return true;
else return false;
}
int operator-(Time &t){
if(this->minutes < t.minutes){
this->hours--;
this->minutes += 60;
}
return this->minutes - t.minutes;
}
};
class Plane{
int flight_number, rem_flight_time = 0, run_way;
Time land_time;
public:
Plane(){};
Plane(int n, int h, int m): flight_number(n), land_time(h, m){}
void schedule(Time time){
rem_flight_time = this->land_time - time;
static int runways[3] = {0, 0, 0};
int min = INT_MAX, runway;
for(int i = 0; i < 3; i++){
if(runways[i] < min){
min = runways[i];
runway = i;
}
}
if(runways[runway] < rem_flight_time) runways[runway] = rem_flight_time;
if(runways[runway] < 10){
run_way = runway + 1;
rem_flight_time = runways[runway];
runways[runway] += 2;
}
else cout<<"All runways occupied, please wait for other planes to land";
}
void land(){
cout<<flight_number<<" please proceed to land in runway "<<run_way<<" in "<<rem_flight_time<<" minutes."<<endl;
}
};
int main(){
Plane boeing(787, 3, 15), jet(345, 3, 18), quin(8434, 3, 20);
Time time(3, 15);
boeing.schedule(time);
jet.schedule(time);
quin.schedule(time);
quin.land();
jet.land();
boeing.land();
return 0;
}
Comments
Leave a comment