4.可以定义点类(Point),再定义一个类(Distance)描述两点之间的距离,其数据成员为两个点类对象,两点

2024-11-25 15:41:57
推荐回答(1个)
回答1:

class Point{
public:
Point(double x=0,double y=0)
:x(x),y(y){
}
void setData(double x0,double y0){
x=x0;
y=y0;
}
double getX(){
return x;
}
double getY(){
return y;
}
double Distance(Point t){
return sqrt((x-t.getX())*(x-t.getX())+(y-t.getY())*(y-t.getY()));
}
~Point(){
}
private:
double x,y;
};

。。。。。。。。。。无语,终于改对了