fork(1) download
  1. class complex_rt;
  2.  
  3. class complex_ab{
  4. friend class complex_rt;
  5.  
  6. public:
  7. complex_ab(): a(0), b(0) { }
  8. complex_ab(const double x, const double y): a(x), b(y) { }
  9. complex_ab(complex_rt);
  10. ~complex_ab() { }
  11.  
  12. private:
  13. double a, b;
  14. };
  15.  
  16. class complex_rt{
  17. friend class complex_ab;
  18. public:
  19. complex_rt(): r(0), theta(0) { }
  20. complex_rt(const double x, const double y): r(x), theta(y) { }
  21. complex_rt(complex_ab);
  22. ~complex_rt() { }
  23.  
  24. private:
  25. double r, theta;
  26. };
  27.  
  28. #include <cmath>
  29. #include <iostream>
  30. using namespace std;
  31.  
  32. complex_ab::complex_ab(complex_rt polar){
  33. a = polar.r * cos(polar.theta);
  34. b = polar.r * sin(polar.theta);
  35. }
  36. complex_rt::complex_rt(complex_ab cart){
  37. r = sqrt(cart.a * cart.a + cart.b * cart.b);
  38. theta = atan(cart.b/cart.a);
  39. }
  40.  
  41. int main() {
  42. }
Success #stdin #stdout 0s 3092KB
stdin
Standard input is empty
stdout
Standard output is empty