#include "complex.h" Complex operator+(Complex a, Complex b) { Complex result; result.re = a.re + b.re; result.im = a.im + b.im; return result; } Complex operator*(Complex a, Complex b) { Complex result; result.re = a.re*b.re - a.im*b.im; result.im = a.re*b.im + a.im*b.re; return result; } Complex operator~(Complex a) { Complex result; result.re = a.re; result.im = -a.im; return result; } Complex::Complex() { re = 0; im = 0; } Complex::Complex(double r) { re = r; im = 0; } Complex::Complex(double r,double i) { re = r; im = i; } std::ostream& operator<<(std::ostream& os, Complex a) { os << a.re << (a.im>=0?"+":"") << a.im << "i"; return os; }