用类做两个坐标,求两点之间距离 C++编程题明天上课就要交了,不交就得挂科,求尽快给以正解,在下感激不进
class Point
{
public: int x;
public: int y;
public double distance(Point p)
{
return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
}
}
int main()
{
Point p1, p2;
p1.x = 1; p1.y = 2;
p2.x = 3; p2.y = 4;
cout << p1.disance(p2);
}
#include <math.h>
#include <iostream.h>
using namespace std;
class Point
{
public: int x;
public: int y;
public: double distance(Point p)
{
return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
}
};
int main()
{
Point p1, p2;
p1.x = 1; p1.y = 2;
p2.x = 3; p2.y = 4;
cout << p1.distance(p2);
}