64,683
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <math.h>
using namespace std;
class point
{private:
float x;
float y;
public:
point():x(0),y(0){};
point(float a,float b):x(a),y(b){};
point(const point &p){ x=p.x; y=p.y;};
virtual float distance(const point &p);
virtual ~point(){};
};
float point::distance(const point &p)
{
float d=sqrt(pow(p.x-x,2)+pow(p.y-y,2));
return d;
}
int main()
{
point a(2,3);
point b(1,1);
float res=a.distance(b);
cout << res << endl;
return 0;
}
cout<<"the distance between point(2,3) and point(1,1) is : " <<res<<endl;
cout<<"点a(2,3)到点b(1,1)之间的距离="<<res<<endl;
class Point
{
friend double length(const Point &,const Point &);
public:
Point(double xx,double yy): x(xx),y(yy) {}
void setx(double xx){x = xx;}
double getx(){return x;}
void sety(double yy){y = yy;}
double gety(){return y;}
private:
double x,y;
};