fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. struct point {
  8. long double x, y;
  9.  
  10. // сложение
  11. point operator+(point const &r) const {
  12. return {x + r.x, y + r.y};
  13. }
  14. point &operator+=(point const &r) {
  15. return *this = *this + r;
  16. }
  17.  
  18. // унарный минус
  19. point operator-() const {
  20. return {-x, -y};
  21. }
  22.  
  23. // вычитание
  24. point operator-(point const &r) const {
  25. return {x - r.x, y - r.y};
  26. }
  27. point &operator-=(point const &r) {
  28. return *this = *this - r;
  29. }
  30.  
  31. // скалярное и векторное произведения
  32. long double operator*(point const &r) const {
  33. return x * r.x + y * r.y;
  34. }
  35. long double operator^(point const &r) const {
  36. return x * r.y - r.x * y;
  37. }
  38.  
  39. long double argument() const {
  40. return atan2(y, x);
  41. }
  42. long double length() const {
  43. return sqrt(x * x + y * y);
  44. }
  45.  
  46. point rotate(long double alpha) const {
  47. return {x * cos(alpha) - y * sin(alpha), x * sin(alpha) + y * cos(alpha)};
  48. }
  49. };
  50.  
  51. int main() {
  52.  
  53. ios_base::sync_with_stdio(false);
  54. cin.tie(nullptr);
  55. cout.tie(nullptr);
  56.  
  57. point a{1, 1}, b{10, -12};
  58. point c = (a + b).rotate(M_PI_2);
  59.  
  60. cout << c.length() << ' ';
  61. cout << fixed << setprecision(10);
  62. cout << c.argument() << '\n';
  63.  
  64. }
  65.  
Success #stdin #stdout 0s 4308KB
stdin
Standard input is empty
stdout
15.5563 0.7853981634