#ifndef COMPLEX_HPP
#define COMPLEX_HPP

#include <math.h>

class Complex {
    friend Complex operator+(const Complex&, const Complex&);
    friend Complex operator-(const Complex&, const Complex&);
    friend Complex operator*(const Complex&, const Complex&);
    friend Complex operator/(const Complex&, const Complex&);
    double re, im;
public:
    Complex(double a_re = 0, double a_im = 0) : re(a_re), im(a_im) {}
    double Magnitude() const { return sqrt(re*re + im*im); }
    double Argument() const { return atan2(im, re); }
    double GetRe() const { return re; }
    double GetIm() const { return im; }
    void Print() const;
};

inline Complex operator+(const Complex &a, const Complex &b)
{
    return Complex(a.re + b.re, a.im + b.im);
}

inline Complex operator-(const Complex &a, const Complex &b)
{
    return Complex(a.re - b.re, a.im - b.im);
}

inline Complex operator*(const Complex &a, const Complex &b)
{
    return Complex(a.re * b.re - a.im * b.im,
                   a.re * b.im + a.im * b.re);
}

inline Complex operator/(const Complex &a, const Complex &b)
{
    double dvs = b.re * b.re + b.im * b.im;
    return Complex((a.re * b.re + a.im * b.im) / dvs,
                   (a.im * b.re - a.re * b.im) / dvs);
}

#endif
