Advertisement
STALKER-FC

Untitled

Jul 2nd, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. class Vector2D
  2. {
  3. public:
  4.     double X;
  5.     double Y;
  6.  
  7.     Vector2D();
  8.     Vector2D(double x, double y);
  9.     Vector2D(const Vector2D &p);
  10.     Vector2D(const Point2D &p1, const Point2D &p2);
  11.     double ScalarProduct(const Vector2D &v);
  12.     bool Collinearity(const Vector2D &v);
  13.     double Length();
  14.     Vector2D& operator= (const Vector2D &v);
  15. };
  16. Vector2D::Vector2D()
  17. {
  18.     X = 0;
  19.     Y = 0;
  20. }
  21. Vector2D::Vector2D(double x, double y)
  22. {
  23.     X = x;
  24.     Y = y;
  25. }
  26. Vector2D::Vector2D(const Vector2D &p)
  27. {
  28.     X = p.X;
  29.     Y = p.Y;
  30. }
  31. Vector2D::Vector2D(const Point2D &p1, const Point2D &p2)
  32. {
  33.     X = p2.X - p1.X;
  34.     Y = p2.Y - p1.Y;
  35. }
  36. istream& operator>>(istream& in, Vector2D &v)
  37. {
  38.     in >> v.X >> v.Y;
  39.     return in;
  40. }
  41. ostream& operator<<(ostream& out, const Vector2D &v)
  42. {
  43.     out << "(" << v.X << ", " << v.Y << ")" << endl;
  44.     return out;
  45. }
  46. Vector2D& Vector2D::operator= (const Vector2D &v)
  47. {
  48.  
  49.     if (this == &v)
  50.         return *this;
  51.     else
  52.     {
  53.         X = v.X;
  54.         Y = v.Y;
  55.         return *this;
  56.     }
  57. }
  58. double Vector2D::ScalarProduct(const Vector2D &v)
  59. {
  60.     return X * v.X + Y * v.Y;
  61. }
  62. bool Vector2D::Collinearity(const Vector2D &v)
  63. {
  64.     if (X / v.X == Y / v.Y)
  65.         return true;
  66.     else
  67.         return false;
  68. }
  69. double Vector2D::Length()
  70. {
  71.     return sqrt(X * X + Y * Y);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement