#ifndef IUGRINA_Complex20061211
#define IUGRINA_Complex20061211

#include <iostream>
#include <string>
#include <cmath>
#include <sstream>

class Complex{

  double im, re;

public:

  Complex():im(0), re(0){}
  Complex(double realni):im(0), re(realni){}
  Complex(double realni, double imaginarni):im(imaginarni), re(realni){}
  Complex(const Complex &z2):im(z2.im) , re(z2.re){}
  
  friend bool operator==( const Complex &z1, const Complex &z2);
  
  bool operator!=( const Complex &z2) const{
    if(im==z2.im && re==z2.re){
      return false;
    }
    
    return true;
  }
  
  Complex& operator=( const Complex &z2){
    im=z2.im;
    re=z2.re;
  }
  
  double& operator[](int i){
    if(i==0){
      return re;
    }
    else if(i==1){
      return im;
    }
    else{
      throw "!!Number is out of range!!";
    }
  }
  
  Complex& operator++(){
    if(im!=0){
      return *this;
    }
    else{
      re++;
      return *this;
    }
  }
 
  Complex operator++(int i){
    if(im!=0){
      return *this;
    }
    else{
      return Complex( re++, im);
    }
  }
  
  Complex& operator--(){
    if(im!=0){
      return *this;
    }
    else{
      re-=1.0;
      return *this;
    }
  }
  
  Complex operator--(int i){
    if(im!=0){
      return *this;
    }
    else{
      return Complex( re--, im);
    }
  }

  operator float(){
    return sqrt(re*re+im*im);
  }

  operator double(){
    return sqrt(re*re+im*im);
  }
  
  operator int(){
    return static_cast<int>( sqrt(re*re+im*im));
  }
  
  operator long(){
    return static_cast<long>( sqrt(re*re+im*im));
  }

  operator std::string(){
    std::ostringstream s;
    s << re << " + i*(" << im << ")";
    
    return s.str();
  }

  friend Complex operator+( const Complex &z1, const Complex &z2);
  friend Complex operator-( const Complex &z1, const Complex &z2);
  friend Complex operator*( const Complex &z1, const Complex &z2);
  
  friend std::ostream& operator<<( std::ostream &iz, const Complex &z);
  friend std::istream& operator>>( std::istream &iz, Complex &z);
  
};

#endif  


