fork download
  1. #include <cmath>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. class Point
  7. {
  8. private://Данные -члены(закрытые)
  9. int x,y;
  10. public: //функции -члены
  11. void set(int new_x,int new_y);
  12. int get_x();
  13. int get_y();
  14. double operator%(Point &pt);
  15. };
  16.  
  17. double Point::operator%(Point &pt)
  18. {
  19. int d1=pt.x-x;
  20. int d2=pt.y-y;
  21. return sqrt((double)(d1*d1+d2*d2));
  22. }
  23.  
  24. int main()
  25. {
  26. Point pt1,pt2;
  27. pt1.set(10,20);
  28. cout<<"pt1 is"<<pt1.get_x();
  29. cout<<","<<pt1.get_y()<<endl;
  30. pt2.set(-5,-25);
  31. cout<<"pt2 is"<<pt2.get_x();
  32. cout<<","<<pt2.get_y()<<endl;
  33. pt1.set(20,20);
  34. pt2.set(24,23);
  35. cout<<"расстояние "<<pt1%pt2;
  36. return 0;
  37. }
  38.  
  39. void Point::set(int new_x,int new_y)
  40. {
  41. if (new_x<0)
  42. new_x*=-1;
  43. if(new_y<0)
  44. new_y*=-1;
  45. x=new_x;
  46. y=new_y;
  47. }
  48.  
  49. int Point::get_x()
  50. {
  51. return x;
  52. }
  53.  
  54. int Point::get_y()
  55. {
  56. return y;
  57. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
pt1 is10,20
pt2 is5,25
расстояние 5