Advertisement
StoneHaos

nastya4

Nov 20th, 2020 (edited)
953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5. #define PI 3.14159265
  6.  
  7. class Complex {
  8. //z = x+yi
  9. public:
  10.     double x, y;
  11.     Complex() {
  12.         this->x = 0;
  13.         this->y = 0;
  14.     }
  15.     Complex(double x, double y) {
  16.         this->x = x;
  17.         this->y = y;
  18.     }
  19.     double mod() {
  20.         return sqrt(this->x * this->x + this->y * this->y);
  21.     }
  22.     void print(bool verbose = true) {
  23.         if (verbose) {
  24.             cout << x;
  25.             if (y < 0)
  26.                 cout << "-";
  27.             else
  28.                 cout << "+";
  29.             cout << fabs(y) << "i\n";
  30.         }
  31.         else {
  32.             cout << x;
  33.             if (y < 0)
  34.                 cout << "-" << -y << "i";
  35.             else if (y > 0)
  36.                 cout << "+" << y << "i";
  37.             cout << "\n";
  38.         }
  39.     }
  40.     Complex sopr() {
  41.         return Complex(this->x, -this->y);
  42.     }
  43.     Complex srt(int n) {
  44.         double r = mod();
  45.         double f = atan(fabs(y / x));
  46.         if (x > 0) {
  47.             if (y < 0)
  48.                 f = 2 * PI - f;
  49.         }
  50.         else if (x == 0) {
  51.             f = PI / 2;
  52.         }
  53.         else {
  54.             if (y > 0)
  55.                 f = PI - f;
  56.             else
  57.                 f = PI + f;
  58.         }
  59.         r = pow(r, 1.0 / n);
  60.         f /= n;
  61.         return Complex(r * cos(f), r * sin(f));
  62.     }
  63.     void read() {
  64.         cout << "z=x+yi, Input x, y: ";
  65.         cin >> x >> y;
  66.     }
  67.  
  68.     Complex operator+(Complex c) {
  69.         return Complex(this->x + c.x, this->y + c.y);
  70.     }
  71.     Complex operator-(Complex c) {
  72.         return Complex(this->x - c.x, this->y - c.y);
  73.     }
  74.     Complex operator*(Complex c) {
  75.         double x = this->x * c.x + (-1 * this->y * c.y);
  76.         double y = this->y * c.x + this->x * c.y;
  77.         return Complex(x, y);
  78.     }
  79.     Complex operator/(Complex c) {
  80.         Complex cc = c.sopr();
  81.         Complex num = *this * cc;
  82.         double denom = (c * cc).x;
  83.         return Complex(num.x / denom, num.y / denom);
  84.     }
  85.     Complex operator++() {
  86.         this->x += 1;
  87.         return *this;
  88.     }
  89.     Complex operator++(int a) {
  90.         this->y += 1;
  91.         return *this;
  92.     }
  93.     ~Complex() {}
  94. };
  95.  
  96. int main(void) {
  97.     Complex a, b, c, d, R;
  98.     a.read();
  99.     a.print();
  100.     b.read();
  101.     b.print();
  102.     c.read();
  103.     c.print();
  104.     d.read();
  105.     d.print();
  106.  
  107.     R = a.srt(3) - (b + c) / a + b * d;
  108.     R.print();
  109.     cout << "mod = " << R.mod() << endl;
  110.     ++R;
  111.     R++;
  112.     R.print();
  113.     return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement