Complex.h

    
#ifndef COMPLEX_H
#define COMPLEX_H
#include < iostream >
#include < cmath >
#include < fstream >
#include < sstream >
#include < vector >

using namespace std; 


class Complex
{
private:
    double re =0,  im = 0, mag = 0;


public:
    Complex();
    Complex(double R, double I);
    ~Complex();

    void set(double R, double I );  // set Re , Im 
    void clr();                     // set to zero Re and Im 

    double abs();                  // absolute value 
    Complex mult(const Complex&) const; // multiply 

    void add(const Complex&);       // add two complex numbers, return to self
    void subtr(const Complex& cpx); // subtract (a+bj) - (c+dj)

    double real() const;             // type Real part
    double imag() const;             // type Imag part
    void type();                   // type complex number 

};

// |konstruktori ::: 
// Complex(R,I),  Complex a
Complex::Complex(double R, double I){
    re = R; 
    im = I; 
}
Complex::Complex(){};
Complex::~Complex(){};


// |postavke ::: 
// | set(R, I), obj.abs(), obj3 = obj.mult(obj2), obj.add(obj2) 

// a.set(R,I)
void Complex::set(double R, double I )
{
         if(re == R && im == I)
        {
         cout << "retyping same No. 2 struct. ?" << endl; 
        }
        else{
            this -> re = R;
            this -> im = I;
        }
}
// a.abs()
double Complex:: abs()
{
   this -> mag = sqrt(re*re + im*im); 
   return mag;
}
// c = a.mult(b) 
Complex Complex::mult(const Complex& cpx) const
{
    Complex C;
    C.re = re*cpx.re - im*cpx.im; 
    C.im = re*cpx.im +  im*cpx.re;
    return C; 
}
// a.add(b)
void Complex:: add(const Complex& cpx)
{
    this-> re += cpx.re;
    this-> im += cpx.im; 

}
// a.subtr(b)
void Complex:: subtr(const Complex& cpx)
{
    this-> re -= cpx.re;
    this-> im -= cpx.im; 

}


// |ispisi ::: 
// |a.real(), a.imag(), a.clr(), a.type()

// a.real()
double Complex:: real() const {

    //cout << "Re: " << this ->re << endl; 
    return this ->re; 
        
}
// a.imag()
double Complex:: imag() const {

//    cout << "Im: " << this ->im << "i" << endl; 
      return this ->im; 
        
}
// a.clr()
void Complex::clr()
{
    this ->re = 0;
    this ->im = 0;

}
// obj.type()
void Complex::type()
{
     cout <<"\n" << re << ((im<0)?"": " + ")  << im << "i"<< endl; 
}


#endif