//Vector.h
//Vector.cppCode:class Vector { public: Vector(); Vector(int, int); void setVector(int, int); int getVectorX()const; int getVectorY()const; double CalcMagn(int, int); void print()const; private: int x; int y; double magnitude; };
main.cppCode:#include "Vector.h" #include <iostream> #include <stdlib.h> #include <math.h> using namespace std; Vector::Vector() { x = 0; y = 0; } Vector::Vector(int Myx, int Myy) { x = Myx; y = Myy; } void Vector::setVector(int Myx, int Myy) { x = Myx; y = Myy; } int Vector::getVectorX() const { return x; } int Vector::getVectorY() const { return y; } double Vector::CalcMagn(int x, int y ) { int doubX = x * x; int doubY = y * y; double magnitude = doubX - doubY; pow(magnitude, 0.5); return magnitude; } void Vector::print()const { cout << "Original value1 = [ " << x << " " << y << " ] " << endl; cout << "The magnitude is " << magnitude << endl; }
I am now doing two Vector and calculator the magnitude of the 2 Vector using class. Right now, i have problem for the pow function.Code:#include <iostream> #include "Vector.H" #include <stdlib.h> #include <math.h> using namespace std; void main(void) { Vector vectorType; vectorType.setVector(5,6 ); vectorType.CalcMagn(5, 6); vectorType.print(); system ("pause"); }
Why is that when i output it, it print -9.25596e + 061 instead of number. I think it might be because the pow only accept double number. But how should I do it that I could calculate using the double variable magnitude instead. Help!!!!!!!!!!!



6Likes
LinkBack URL
About LinkBacks



