#include class Complex { public: Complex(double real = 0.0, double imag = 0.0) : real{real}, imag{imag} { } Complex operator+(const Complex &other) const { return Complex{real + other.real, imag + other.imag}; } Complex operator*(const Complex &other) const { return Complex{real * other.real - imag * other.imag, real * other.imag + imag * other.real}; } friend std::ostream &operator<<(std::ostream &os, const Complex &c) { os << c.real; if (c.imag >= 0) { os << "+"; } os << c.imag << "i"; return os; } private: double real; double imag; }; 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; }