Скачиваний:
13
Добавлен:
01.05.2014
Размер:
946 б
Скачать
#include "vector.h"

vector::vector() : x(0), y(0) {}

vector::vector(double x_, double y_) : x(x_), y(y_) {}

vector operator+ (vector &lhs,vector &rhs)
{
	return vector( lhs.x + rhs.x, lhs.y + rhs.y );
}

vector operator- (vector &lhs,vector &rhs)
{
	return vector( lhs.x - rhs.x, lhs.y - rhs.y );
}

vector operator- (vector &rhs)
{
	return vector( -rhs.x, -rhs.y );
}

double operator* (vector &lhs,vector &rhs)
{
	return lhs.x * rhs.x + lhs.y * rhs.y;
}

vector operator* (double d,vector &rhs)
{
	return vector( d * rhs.x, d * rhs.y );
}

vector operator* (vector &lhs,double d)
{
	return vector( lhs.x * d, lhs.y * d );
}

vector operator/ (vector &lhs,double d)
{
	return vector( lhs.x / d, lhs.y / d );
}

ostream& operator<< (ostream& os,vector &rhs)
{
	return os << "[ " << rhs.x << " , " << rhs.y << " ]";
}

double norma(vector &lhs)
{
	return sqrt( lhs.x * lhs.x + lhs.y * lhs.y );
}
Соседние файлы в папке all