Это реальный вопрос. Создайте объект данного класса: AirPlaneGenerator, который будет генерировать и возвращать объект AirPlane всякий раз, когда истекло время интервала (заданного во время создания экземпляра). ПРИМЕЧАНИЕ: генератор возвращает NULL между интервалами; что ни один самолет в настоящее время не приземляется. Это файл cpp для файла генератора аэропорта
#include "airplanegenerator.h"
// initialize the static list of tasks
vector<AirPlane> AirPlaneGenerator::lstPlanes(0);
// -- Constructors --
// default constructor
AirPlaneGenerator::AirPlaneGenerator(int i) {
// initialise all airplanes within the list
this->interval = i;
this->cursor = 0;
this->elapsed = 0;
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_GOVERNMENT));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_VIP));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_GOVERNMENT));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_VIP));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_VIP));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_SMALLPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_SMALLPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_SMALLPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_VIP));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_LARGEPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_LARGEPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_SMALLPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_GOVERNMENT));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_LARGEPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_GOVERNMENT));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_GOVERNMENT));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_LARGEPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_SMALLPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_MAIL));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_SMALLPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_VIP));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_GOVERNMENT));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_LARGEPASS));
AirPlaneGenerator::lstPlanes.insert(AirPlaneGenerator::lstPlanes.end(), new
AirPlane(JFF_GOVERNMENT));
cout << " GENERATOR: AirPlanes Are Ready For Landing." << endl;
}
// -- Other Interfaces --
// get the next task in the list
AirPlane* AirPlaneGenerator::getNext() {
// find out the current elapsed time
this->elapsed += 1;
// return an airplane if the elapsed time exceeds the current cursor position
if (this->elapsed / this->interval >= 1) {
this->elapsed -= this->interval;
if (this->cursor < TOTALPLANES) {
cout << " GENERATOR: AirPlane# " <<
AirPlaneGenerator::lstPlanes[this->cursor].getIdnum() << " Now Landing." << endl;
return &(AirPlaneGenerator::lstPlanes[this->cursor++]);
} else {
cout << " GENERATOR: No More AirPlanes In The Air To Land." << endl;
return NULL;
}
} else {
cout << " GENERATOR: No AirPlane Landing Now." << endl;
return NULL;
}
}
Вопрос: вам нужно реализовать Creational Pattern (Factory Pattern), который будет создавать объект класса после заданного интервала времени.