fork download
  1. #include "pch.h"
  2. #include <algorithm>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. class Point //класс
  8. {
  9. private:
  10. double x; //поле
  11. double y;
  12.  
  13. public:
  14. void set_y(double yy)
  15. {
  16. y = yy;
  17. }
  18.  
  19. Point()
  20. {
  21. }
  22.  
  23. Point(double xx, double yy = 5) //конструктор
  24. : x(xx), y(yy)
  25. {
  26. if (x < 0)
  27. x = 0;
  28. if (y < 0)
  29. y = 0;
  30. }
  31.  
  32. double dist() //метод
  33. {
  34. return sqrt(x * x + y * y);
  35. }
  36.  
  37. double scl(Point other)
  38. {
  39. return x * other.x + y * other.y;
  40. }
  41.  
  42. void print()
  43. {
  44. cout << x << " " << y << endl;
  45. }
  46.  
  47. Point operator+(Point other) // Перегрузка оператора +
  48. {
  49. return Point(x + other.x, y + other.y);
  50. }
  51.  
  52. Point operator+(double other)
  53. {
  54. return Point(x + other, y + other);
  55. }
  56.  
  57. bool operator<(Point other) //this < other
  58. // Перегрузка оператора <
  59. {
  60. return x < other.x || (x == other.x && y < other.y);
  61. }
  62.  
  63. };
  64.  
  65. int main()
  66. {
  67. Point p1(4.2, 5.3); // экземпляр структуры (объект)
  68.  
  69. Point p2(12);
  70. p2.set_y(3.5);
  71.  
  72. Point p3 = p1 + p2;
  73. p3.print();
  74. Point p4 = p1 + 3.0;
  75. p4.print();
  76.  
  77. Point points[3];
  78. points[0] = Point(1, 3);
  79. points[1] = Point(5, 1);
  80. points[2] = Point(2, 5);
  81.  
  82. sort(points, points + 3); // Нужна перегрузка оператора <
  83. for (int i = 0; i < 3; i++)
  84. points[i].print();
  85. }
  86.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:10: fatal error: pch.h: No such file or directory
 #include "pch.h"
          ^~~~~~~
compilation terminated.
stdout
Standard output is empty