C++编程题~帮帮忙好吗?

2024-12-05 02:59:50
推荐回答(1个)
回答1:

#include
#include
class CMyPoint
{
public:

CMyPoint(int x = 0, int y =0)
{
m_x = x;
m_y = y;
}
void SetValue(int x,int y)
{
m_x = x;
m_y = y;
}
void Display()

{
cout << "(" << m_x << "," << m_y << ")" << endl;
}
friend double distance(CMyPoint & p1, CMyPoint & p2);
protected:
private:
int m_x;
int m_y;
};
double distance(CMyPoint & p1, CMyPoint & p2)
{
double dbldistance;
dbldistance = sqrt((p1.m_x - p2.m_x)*(p1.m_x - p2.m_x) + (p2.m_x - p2.m_y)*(p2.m_x - p2.m_y));

return dbldistance;

}
void main()
{
CMyPoint p;
p.SetValue(123,456);
p.Display();
CMyPoint p2(456,123);
p2.Display();
cout << distance(p,p2) << endl;

}