#include class Complex { public: Complex(double real, double imag) : real { real }, imag { imag } { } double get_real() const { return real; } double get_imag() const { return imag; } Complex operator+(Complex const& rhs) const { return { real + rhs.real, imag + rhs.imag }; } Complex operator*(Complex const& rhs) const { return { real * rhs.real - imag * rhs.imag, real * rhs.imag + imag * rhs.real }; } private: double real; double imag; }; std::ostream& operator<<(std::ostream& os, Complex const& complex) { os << complex.get_real() << "+" << complex.get_imag() << "i"; return os; } int main() { Complex a{1.0, 2.0}; Complex const b{3.0, 4.0}; std::cout << "a = " << a << std::endl; std::cout << "b = " << b << std::endl; std::cout << "a + b = " << a + b << std::endl; std::cout << "a * b = " << a * b << std::endl; return 0; }