I'm practicing with classes and I created a program that creates a vector and calculates the magnitude of it. I separated the code so that one class is a vector class and a different class handles the math. My question is, is this incorrect? I have to instantiate my math class in order to be able to use it, and it looks clunky, even though it works.
Main:
int main()
{
// Instantiate math library... ?
Math math; // <-- Instantiating math library here
Vector3D *test = new Vector3D("Test vector 1", 0, 0, 1);
printVector(test);
// Calling math library to calculate magnitude
std::cout << "Test vector 1 magnitude: " << math.magnitude(test) << std::endl;
return 0;
}
Vector Class:
class Vector3D {
private:
std::string name;
double x;
double y;
double z;
public:
Vector3D();
Vector3D(std::string, double, double, double);
// Setters
void setName(std::string);
void setX(double);
void setY(double);
void setZ(double);
// Getters
std::string getName() const;
double getX() const;
double getY() const;
double getZ() const;
// Operators
Vector3D& operator *=(double s); // Scalar multiplication
Vector3D& operator /=(double s); // Scalar division
};
Math Class:
class Math {
public:
double magnitude(const Vector3D* v);
};