c++程序定义一个点类Point

2024-10-29 09:24:37
推荐回答(1个)
回答1:

class Point {
private:
double x;
double y;
public:
Point();
Point(double x1, double y1) {x=x1;y=y1}
void set(double x1, double y1) {x=x1;y=y1}
void Display() {cout << "(x,y)=(" << x << "," << y << ")" << endl;
void move(double x1, double y1) {x=x1;y=y1}
double getx() {return x;}
double gety() { return y;}
double Distance(Point &p) {
return sqrt( pow((p.getx()-x), 2) + pow((p.gety()-y),2));

}

};