1
0

vect.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // vect.h -- Vector class with <<, mode state
  2. #ifndef VECTOR_H_
  3. #define VECTOR_H_
  4. #include <iostream>
  5. namespace VECTOR
  6. {
  7. class Vector
  8. {
  9. public:
  10. enum Mode {RECT, POL};
  11. // RECT for rectangular, POL for Polar modes
  12. private:
  13. double x; // horizontal value
  14. double y; // vertical value
  15. double mag; // length of vector
  16. double ang; // direction of vector in degrees
  17. Mode mode; // RECT or POL
  18. // private methods for setting values
  19. void set_mag();
  20. void set_ang();
  21. void set_x();
  22. void set_y();
  23. public:
  24. Vector();
  25. Vector(double n1, double n2, Mode form = RECT);
  26. void reset(double n1, double n2, Mode form = RECT);
  27. ~Vector();
  28. double xval() const {return x;} // report x value
  29. double yval() const {return y;} // report y value
  30. double magval() const {return mag;} // report magnitude
  31. double angval() const {return ang;} // report angle
  32. void polar_mode(); // set mode to POL
  33. void rect_mode(); // set mode to RECT
  34. // operator overloading
  35. Vector operator+(const Vector & b) const;
  36. Vector operator-(const Vector & b) const;
  37. Vector operator-() const;
  38. Vector operator*(double n) const;
  39. // friends
  40. friend Vector operator*(double n, const Vector & a);
  41. friend std::ostream & operator<<(std::ostream & os, const Vector & v);
  42. };
  43. } // end namespace VECTOR
  44. #endif