The air traffic controllers are in trouble. They need a new system for keeping track of planes in their local airspace, and you have been contacted to design such a system. After taking out gobs of insurance, you agree.
This task has two parts:
Plane class,
based on the description below. You should submit a sufficiently documented file called
plane.h that defines it.
plane.h file, and then linked with your implementation. You will not be
allowed to change the program we provide.
Planes are tracked using a 2D system that keeps (in kilometers) their altitude and their range (note that a real ATC system would require three dimensions, however for the sake of simplicity we will use only two dimensions. Do not try to extend the project for 3D). In this system, then, two planes at the same height and range will collide.
Each instance of your plane class should have information about its current position, and its current velocity, and each plane should have a flag which will be true if the plane is too close to any other planes. In addition, each plane should keep a list of pointers to all the planes it is too close to. Finally, every plane has a unique number (purely an integer) as an id.
The position should be kept as a coordinate, which should be represented as a class (see vector.h):
// 2D cartesian coordinate class
class Coord {
public:
// the class is so simple there's no need to make anything private
float x,y;
float distance(Coord) const; // distance between two points
// constructors
Coord(float,float); // initialize data
Coord(); // sets x,y to 0,0
// I/O - note that these don't need to be friends.
friend ostream& operator<<(ostream& s, const Coord& p);
friend istream& operator>>(istream& i, Coord& p);
};
Velocity vectors have speed and direction components, and should be represented as a class (see vector.h):
// a direction/magnitude vector for airspeed.
class VelocityVector {
private:
float speed; // kps
float direction; // an angle in radians, between 0 and 2pi;,
// where 0 is flying level, from left to right.
public:
// accessor methods
float getSpeed() const; // returns speed in KPH
float getDirection() const; // returns direction in degrees
void setSpeed(float); // input in KPH
void setDirection(float); // input is in degrees
// basic computation - given an initial coordinate,
// return a new coordinate which is the result of
// moving from the initial coordinate along the vector.
Coord computeTranslation(Coord) const;
// I/O note that these don't need to be friends since
// they use the accessor methods anyway.
friend ostream& operator<<(ostream&,const VelocityVector&);
friend istream& operator>>(istream&,VelocityVector&);
// Constructors
VelocityVector(); // default constructor sets data to 0
VelocityVector(float s, float d); // initializes the data
};
Implementations of these two classes will be provided to you (see vector.h, and vector.o in the directory ~cs102/sim ).
Planes should also have several methods:
checkProximity: should take a list of pointers to planes as
a parameter and should check if any of the planes in that list are "too close". Define
a class constant that will represent what distance is too close. This function should set
the flag for the plane if any other planes are too close, and for each plane that is too
close, should add it to the private list of planes that are too close. Note that one
of the pointers in the input parameter list will probably be a pointer to the plane the
method is invoked on. This function should return nothing.
computeNextPosition: should not change the instance. This should return the
position the plane will be after moving along its current vector. No parameters.
setNextPosition: should set the position of the plane to be the position
after moving along its current vector. No parameters.
getSpeed: should return the speed of the plane's velocity vector in kph.
getDirection: should return the angle of the plane's velocity vector in degrees.
getNumber: should return the id number of the plane.
setSpeed: should set the speed of the plane's vector. Returns nothing, takes
a float that represents the new speed in kph.
setDirection: should set the direction of the plane's vector. Returns nothing,
takes a float that represents the new direction (in degrees).
outOfRange: should return true if the plane is out of range of the current ATC center. Define two class constants to represent this range. This function takes no parameters.