nicuvlad76

Untitled

Dec 10th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. Complex::Complex(){r=0;i=0;}
  2. Complex::Complex(int pr, int pi){r=pr; i=pi;}
  3. void Complex::set(int pr, int pi){r=pr;i=pi;}
  4. double Complex::modul(){ return sqrt(r*r+i*i);}
  5. int Complex::real(){return r;}
  6. int Complex::imag(){return i;}
  7. ostream& operator<<(ostream& out, const Complex& c)
  8. {
  9. if(c.r!=0 || c.i==0) out<<c.r;
  10. if(c.i>0 && c.r!=0) out<<"+";
  11. if(c.i!=0) out<<c.i<<"i";
  12. return out;
  13. }
  14. Complex Complex::operator +(Complex b)
  15. {
  16. Complex c;
  17. c.set(this->r+b.real(),this->i+b.imag());
  18. return c;
  19. }
  20. Complex Complex::operator -(Complex b)
  21. {
  22. Complex c;
  23. c.set(this->r-b.real(),this->i-b.imag());
  24. return c;
  25. }
  26. Complex Complex::operator *(Complex b)
  27. {
  28. Complex c;
  29. c.set(this->r*b.real()-this->i*b.imag(),this->i*b.real()+this->r*b.imag());
  30. return c;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment