mfgnik

Untitled

Dec 14th, 2020 (edited)
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <cmath>
  4.  
  5. struct ComplexPolar;
  6.  
  7.  
  8. struct Complex {
  9.     double a, b;
  10.  
  11.     ComplexPolar GetComplexPolar();
  12.  
  13.     void Print() {
  14.         std::cout << a << " + " << b << " * i" << std::endl;
  15.     }
  16. };
  17.  
  18.  
  19. struct ComplexPolar {
  20.     double r, phi;
  21.     Complex GetComplex() {
  22.         return Complex{r * std::cos(phi), r * std::sin(phi)};
  23.     }
  24.  
  25.     void Print() {
  26.         std::cout << r << "(cos(" << phi << ") + sin(" << phi << "))" << std::endl;
  27.     }
  28. };
  29.  
  30.  
  31. ComplexPolar Complex::GetComplexPolar() {
  32.     return ComplexPolar{std::sqrt(a * a + b * b), std::atan(b / a)};
  33.  
  34. }
  35.  
  36. int main() {
  37.  
  38.     ComplexPolar a{1, 2};
  39.     a.Print();
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment