@rjryan94
Have you tried using the debugger? It's just that looking at over 200 LOC, to find runtime errors takes too long. Much quicker with a debugger to see where things go wrong.
Something to investigate is the operator they are all + in the output.
I have some advice to make your code better, though.
Remember that class functions have direct access to member variables, so no need to use get / set functions from within the class function, like you do here for example:
1 2 3 4 5
|
void Complex::Init(double pInitReal, double pInitImag)
{
SetReal(pInitReal);
SetImag(pInitImag);
}
|
Also, consider using initialisation rather than assignment in your functions - you may not need the Init function at all:
1 2 3
|
Complex::Complex() : mReal(0.0), mImag(0.0){}
Complex::Complex(double pInitReal, double pInitImag): mReal(pInitReal), mImag(pInitImag){}
|
It is worth explicitly in-lining very trivial functions:
inline double Complex::GetImag() const { return mImag;}
Having said that, be careful with in-lining, it's probably only worth it for very trivial functions like this one.
So now you can do this:
double prodReal = mReal * pRHSOp.GetReal() - mImag * pRHSOp.GetImag();
Even better would be to overload the operators in the class, rather than writing functions for them.
With lines 31 - 48 in ComplexTest.cpp, consider using a switch instead, with the division operation being a case. That way you can use the default clause to catch bad input, rather than the division. Always use the else of default to catch bad input. I prefer to use a switch whenever I can (for integral types).
Another thing is that it is a common convention to use a leading 'p' in a variable name that means that it is a pointer type.
Hope all goes well.