Advertisement
Guest User

Untitled

a guest
May 24th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #ifndef complex_h
  2. #define complex_h
  3. #include<iostream>
  4. #include<string>
  5. #include<math.h>
  6. using namespace std;
  7. class Complex {
  8. private:
  9.     float re, im;
  10.     float abs, arg;
  11. public:
  12.     Complex() {
  13.         re = 0;
  14.         im = 0;
  15.         abs = 0;
  16.         arg = 0;
  17.     }
  18.     Complex(float re, float im)
  19.     {
  20.         this->re = re;
  21.         this->im = im;
  22.         abs = sqrt(re*re + im * im);
  23.         arg = atan(im / re);
  24.     }
  25.     Complex(const Complex &complex) :
  26.         re(complex.re), im(complex.im), abs(complex.abs), arg(complex.arg)
  27.     {
  28.         cout << "Copy constructor worked here" << endl;
  29.     }
  30.     Complex& operator=(Complex& c1) {
  31.         if (this == &c1)
  32.             return *this;
  33.         re = c1.re;
  34.         im = c1.im;
  35.         abs = c1.abs;
  36.         arg = c1.arg;
  37.         return *this;
  38.     }
  39.     bool operator==(Complex c) {
  40.         return abs == c.abs;
  41.     }
  42.     bool operator !=(Complex c) {
  43.         return abs != c.abs;
  44.     }
  45.     bool operator >(Complex c) {
  46.         return abs > c.abs;
  47.     }
  48.     bool operator <(Complex c) {
  49.         return abs < c.abs;
  50.     }
  51.     friend ostream& operator<<(ostream& out, Complex &c) {
  52.         out << "The module of complex number is " << c.abs << endl;
  53.         out << "The argumebt of complex number is " << c.arg << endl;
  54.         return out;
  55.     }
  56.     friend istream& operator>>(istream& in, Complex &c) {
  57.         cout << "Enter the real axis of number: ";
  58.         in >> c.re;
  59.         cout << "Enter the imaginary axis of number: ";
  60.         in >> c.im;
  61.         c.abs = sqrt(c.re*c.re + c.im * c.im);
  62.         c.arg = atan(c.im / c.re);
  63.         return in;
  64.     }
  65.     Complex& operator++() {
  66.         im++;
  67.         re++;
  68.         abs = sqrt(re*re + im * im);
  69.         arg = atan(im / re);
  70.         return *this;
  71.     }
  72.  
  73.     Complex& operator++() {
  74.         Complex oldValue(im, re);
  75.         im++;
  76.         re++;
  77.         abs = sqrt(re*re + im * im);
  78.         arg = atan(im / re);
  79.         return oldValue;
  80.     }
  81.  
  82.     Complex & operator--() {
  83.         im--;
  84.         re--;
  85.         abs = sqrt(re*re + im * im);
  86.         arg = atan(im / re);
  87.         return *this;
  88.     }
  89.     void setData() {
  90.         cout << "Enter the real axis of number: ";
  91.         cin >> re;
  92.         cout << "Enter the imaginary axis of number: ";
  93.         cin >> im;
  94.         abs = sqrt(re*re + im * im);
  95.         arg = atan(im / re);
  96.     }
  97.     ~Complex(){
  98.         cout << "Class complex was destructed." << endl;
  99.     }
  100.     void getComplex() {
  101.         cout << "The module of complex number is " << abs << endl;
  102.         cout << "The argumebt of complex number is " << arg << endl;
  103.     }
  104.  
  105. };
  106.  
  107.  
  108. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement