compare magnitude of two vectors
How do I correct to compare the values of the vectors ??? The length I figured, I can not compare))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
class Vector
{
float x, y, z;
public:
Vector();
Vector(const Vector&a);
Vector(float mx, float my, float mz);
Vector&operator=(const Vector&a);
Vector&operator+(const Vector&a)const;
Vector&operator-(const Vector&a)const;
Vector&operator*(float a)const;
Vector&operator*(const Vector&a)const;
inline float Magnitude();
void show();
void showMag();
~Vector();
};
bool operator<(const Vector&lhs,const Vector&rhs);
bool operator>(const Vector&lhs, const Vector&rhs);
/*.......*/ implementation
Vector & Vector::operator*(const Vector & a) const
{
return Vector(x*a.x, y*a.y, z*a.z);
}
inline float Vector::Magnitude()
{
return sqrt(x*x+y*y + z*z);
}
void Vector::show()
{
cout << x << " " << y << " " << z;
}
void Vector::showMag()
{
cout << Magnitude();
}
Vector::~Vector()
{
}
bool operator<(const Vector & lhs, const Vector & rhs)
{
return (lhs < rhs); // ?????
}
bool operator>(const Vector & lhs, const Vector & rhs)
{
return lhs > rhs; // ????
}
int main()
cout << "\nMagnitude vector1\n";
ob1.Magnitude();
ob1.showMag();
cout << "\nMagnitude vector2\n";
ob2.Magnitude();
ob2.showMag();
????????
|
Last edited on
Topic archived. No new replies allowed.