fork download
  1. #include <iostream>
  2. #include<cmath>
  3. using namespace std;
  4.  
  5. class Point{
  6. double x, y;
  7. public:
  8. Point(double x=0, double y=0){
  9. this->x=x;
  10. this->y=y;
  11. }
  12.  
  13. float operator-(const Point& p2){
  14. return sqrt((x-p2.x)*(x-p2.x)+(y-p2.y)*(y-p2.y));
  15. }
  16.  
  17. };
  18.  
  19.  
  20. int main()
  21. {
  22. Point p1(5, 4), p2(3.5, -2.5);
  23. float distance=p1-p2;
  24. cout<<distance;
  25.  
  26.  
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
6.67083