I've made a program for my OOP class that does the following:
- Defines a class to represent complex numbers
- Uses a constructor to initialize a Complex Number object
- passes and returns complex number objects from a function
- tests the complex number class in a driver, and
- optionally adds and subtracts complex numbers.
My Program works as follows:
- Prompts the user to Enter in the values for the real and imaginary parts of a complex number.
- Creates a ComplexNumber object using the user provided values as parameters to the ComplexNumber constructor.
- Prints the value of the complex number object, using the stand-alone print function.
I'm a little confused at this requirement though:
static void printComplexNumber(ComplexNumber n)
The function will print the Complex Number object passed as a parameter in the form
realPart + imaginaryPart i
The
realPart
should be signed only if it is negative. The sign between therealPart
and theimaginaryPart
should be positive if theimaginaryPart
is positive, and negative if theimaginaryPart
is negative. If the real part is zero, only print the imaginary part, with the corrrect sign. If the imaginary part is zero, only print the real part. If the imaginary part is equal to one, just print the symboli
for the imaginary part.
Here's my question: What's the best(most efficient, clear, concise) way to determine when to print what?
My Code for my Print method:
static void PrintComplexNumber(ComplexNumber n)
{
// what's the best thing to do here to determine what to print?
// if-else?
// to get my real value and complex value, I have methods of the
// ComplexNumber class entitled: GetRealPart(), and GetComplexPart().
}