Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Vector2D
- {
- public:
- double X;
- double Y;
- Vector2D();
- Vector2D(double x, double y);
- Vector2D(const Vector2D &p);
- Vector2D(const Point2D &p1, const Point2D &p2);
- double ScalarProduct(const Vector2D &v);
- bool Collinearity(const Vector2D &v);
- double Length();
- Vector2D& operator= (const Vector2D &v);
- };
- Vector2D::Vector2D()
- {
- X = 0;
- Y = 0;
- }
- Vector2D::Vector2D(double x, double y)
- {
- X = x;
- Y = y;
- }
- Vector2D::Vector2D(const Vector2D &p)
- {
- X = p.X;
- Y = p.Y;
- }
- Vector2D::Vector2D(const Point2D &p1, const Point2D &p2)
- {
- X = p2.X - p1.X;
- Y = p2.Y - p1.Y;
- }
- istream& operator>>(istream& in, Vector2D &v)
- {
- in >> v.X >> v.Y;
- return in;
- }
- ostream& operator<<(ostream& out, const Vector2D &v)
- {
- out << "(" << v.X << ", " << v.Y << ")" << endl;
- return out;
- }
- Vector2D& Vector2D::operator= (const Vector2D &v)
- {
- if (this == &v)
- return *this;
- else
- {
- X = v.X;
- Y = v.Y;
- return *this;
- }
- }
- double Vector2D::ScalarProduct(const Vector2D &v)
- {
- return X * v.X + Y * v.Y;
- }
- bool Vector2D::Collinearity(const Vector2D &v)
- {
- if (X / v.X == Y / v.Y)
- return true;
- else
- return false;
- }
- double Vector2D::Length()
- {
- return sqrt(X * X + Y * Y);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement