CS 102 Assignment #7

Note:Changes were made to this description on 4/7.

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:

  1. Due: April 13 Design the complete interface for the Plane class, based on the description below. You should submit a sufficiently documented file called plane.h that defines it.

  2. Due: April 20 Implement the class. You will be provided with a program that will run with your full class implementation (see ~cs102/sim/sim.C ). This program must be compiled with your 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: