📄 test.cpp
字号:
#include "Plane.h"
#include "Random.h"
#include "Runway.h"
#include "Base.h"
// Section 3.5:
int main() // Airport simulation program
/*
Pre: The user must supply the number of time intervals the simulation is to
run, the expected number of planes arriving, the expected number
of planes departing per time interval, and the
maximum allowed size for runway queues.
Post: The program performs a random simulation of the airport, showing
the status of the runway at each time interval, and prints out a
summary of airport operation at the conclusion.
Uses: Classes Runway, Plane, Random and functions run_idle, initialize.
*/
{
int end_time; // time to run simulation
int queue_limit; // size of Runway queues
int flight_number = 0;
double arrival_rate, departure_rate;
initialize(end_time, queue_limit, arrival_rate, departure_rate);
Random variable;
Runway airport_for_landing(queue_limit);
Runway airport_for_takeoff(queue_limit);
for (int current_time = 0; current_time < end_time; current_time++) { // loop over time intervals
int number_arrivals = variable.poisson(arrival_rate); // current arrival requests
for (int i = 0; i < number_arrivals; i++) {
Plane current_plane(flight_number++, current_time, arriving);
if (airport_for_landing.can_land(current_plane) != success)
current_plane.refuse();
}
int number_departures= variable.poisson(departure_rate); // current departure requests
for (int j = 0; j < number_departures; j++) {
Plane current_plane(flight_number++, current_time, departing);
if (airport_for_takeoff.can_depart(current_plane) != success)
current_plane.refuse();
}
Plane fly_plane;
Plane land_plane;
if(airport_for_landing.canfly(current_time, fly_plane)==fly)
// Let at most one Plane onto the Runway at current_time.
fly_plane.fly(current_time);
else
if (airport_for_takeoff.canland(current_time, land_plane)==land)
land_plane.land(current_time);
if (airport_for_takeoff.canland(current_time, land_plane)==land)
// Let at most one Plane onto the Runway at current_time.
land_plane.land(current_time);
else
if(airport_for_landing.canfly(current_time, fly_plane)==fly)
fly_plane.fly(current_time);
}
cout<<"Information of the airport for landing:"<<endl;
airport_for_landing.shut_down(end_time);
cout<<"**************************************************"<<endl;
cout<<"Information of the airport for taking off:"<<endl;
airport_for_takeoff.shut_down(end_time);
system("pause");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -