The obvious approach most Vector3D classes use it to represent the data in one form and convert from input in another form into it (e.g. leave the vector in cartesian for and convert from spherical and cylindrical input). Depending on the problem that is a viable solution [not always].
Then it is a matter of doing one thing at a time. I would actually recommend writing the output first, that greatly helps with debugging, so you have a class like this:
class Vector3D
{
private:
double x,y,z; // This can be done in many ways,but I have chosen discrete
// values. [you can use an array, etc]
public:
Vector3D(); // Default constructor [e.g. set x,y,z to zero]
Vector3D(const Vector3D&); // ALWAYS write a copy constructor
Vector3D& operator=(const Vector3D&); // ALWAYS write an assignment operator
~Vector3D() {} // Destructor
void write(std::ostream&) const; // Write should be constant
};
// This is implemented in the standard way
std::ostream& operator<<(std::ostream& OutStream,const Vector3D& A)
{
A.write(OutStream);
return OutStream;
}
Then all you have to write is a simple write method and the constructors/copy constructors and you can star doing stuff with your class. Initially, the vector 0,0,0 is a bit boring, so you start to increase the scope, e.g. an constructor that takes three values, test that and build up the class.
After a bit you add this:
class Vector3D
{
// stuff....
public:
// stuff...
Vector3D& operator+=(const Vector3D&);
Vector3D operator+(const Vector3D&,const Vector3D&) const;
// then to multiply by a …