// Fig. 4.7: complex1.cpp // Member function definitions for class Complex #include using std::cout; #include "complex1.h" // Constructor Complex::Complex( double r, double i ) : real( r ), imaginary( i ) { } // Overloaded addition operator Complex Complex::operator+( const Complex &operand2 ) const { return Complex( real + operand2.real, imaginary + operand2.imaginary ); } // Overloaded subtraction operator Complex Complex::operator-( const Complex &operand2 ) const { return Complex( real - operand2.real, imaginary - operand2.imaginary ); } // Overloaded = operator const Complex& Complex::operator=( const Complex &right ) { real = right.real; imaginary = right.imaginary; return *this; // enables cascading } // Display a Complex object in the form: (a, b) void Complex::print() const { cout << '(' << real << ", " << imaginary << ')'; }