fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. class point
  6. {
  7. double x, y;
  8. public: point(double a, double b) { x = a; y = b; }
  9. friend double Distance(const point& p1, const point& p2);
  10. };
  11. double Distance(const point& p1, const point& p2)
  12. {
  13. return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
  14. }
  15. int main()
  16. {
  17. point p1(1,1), p2(2,2);
  18. cout << Distance(p1, p2) << endl;
  19. return 0;
  20. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
1.41421