#include #include using namespace std; class Complex { public: Complex(double re,double im) :real(re),imag(im) {}; Complex operator+(const Complex& other); Complex operator=(const Complex& other); void print(); private: double real; double imag; }; Complex Complex::operator+(const Complex& other) { double result_real = real + other.real; double result_imaginary = imag + other.imag; return Complex( result_real, result_imaginary ); } void Complex::print() { cout << real << "+" << imag << "i" << endl; } //--------------------------------------- main() int main() { Complex a(1.2,1.3); //this class is used to represent complex numbers cout << "a = "; a.print(); cout << endl; Complex b(2.1,3); //notice the construction taking 2 parameters for the real and imaginary part cout << "b = "; b.print(); cout << endl; Complex c = a+b; //for this to work the addition operator must be overloaded cout << "c = "; c.print(); cout << endl; }