#include "complex.hpp" Complex::Complex(double x, double y) :_real(x), _imag(y) {} double Complex::get_real() const { return this->_real; } double Complex::get_imag() const { return this->_imag; } void Complex::set_real(const double &x) { this->_real = x; } void Complex::set_imag(const double &y) { this->_imag = y; } void Complex::write(ostream &ostr) const { if (_real != 0) ostr << _real; if (_imag != 0) { if (_imag < 0) ostr << _imag << "i"; else ostr << "+" << _imag << "i"; } } void Complex::read(istream &istr) { double x, y; char c; istr >> x >> y >> c; if (c != 'i') throw "Neuspeno ucitavanje kompleksnog broja"; _real = x; _imag = y; } Complex Complex::operator+(const Complex &q) const { return Complex(_real + q._real, _imag + q._imag); } Complex Complex::operator-(const Complex &q) const { return Complex(_real - q._real, _imag - q._imag); } Complex Complex::operator*(const Complex &q) const { return Complex(_real * q._real - _imag * q._imag, _real * q._imag + _imag * q._real); } bool Complex::operator==(const Complex &q) const { return _real == q._real && _imag == q._imag; } bool Complex::operator!=(const Complex &q) const { return !((*this)==q); } ostream& operator<<(ostream &ostr, const Complex &p) { p.write(ostr); return ostr; } istream& operator>>(istream &istr, Complex &p) { p.read(istr); return istr; } Complex::operator int() const { return 0; }