// // // // #include #include "complex.h" using namespace std; // member function definitions below Complex::Complex() // sets complex number equal to 0 { real = 0; imag = 0; } Complex::Complex(int r, int im) // allow user to specify the complex number by passing parameters { Set(r, im); } void Complex::Set(int r, int im) { real = r; imag = im; } int Complex::GetReal() const { return real; } int Complex::GetImag() const { return imag; } void Complex::Show() const { if ((real != 0) && (imag != 0)) // both parts present { cout << real << " + " << imag << 'i'; } else if ((real != 0) && (imag == 0)) // only real part exists cout << real; else if ((real == 0) && (imag != 0)) // only imag part exists cout << imag << 'i'; else // else value is 0. cout << '0'; }