65,211
社区成员
发帖
与我相关
我的任务
分享#include <iostream>
#include <math.h>
using namespace std;
class CPostion
{
public:
CPostion(){}
CPostion(float xx,float yy):x(xx),y(yy){}
void Move(float newx,float newy)
{
x = newx;
y = newy;
}
float GetDistance(const CPostion & cp)
{
return pow(pow(x-cp.x,2)+pow(y-cp.y,2),0.5);
}
float GetX(){return x;}
float GetY(){return y;}
protected:
private:
float x;
float y;
};
int main()
{
CPostion cp;
CPostion cp2(1,3);
cp.Move(3,5);
cout<<cp.GetX()<<","<<cp.GetY()<<endl;
cout<<cp.GetDistance(cp2)<<endl;
return 0;
}