class Point{ private: double x; double y; public: Point(double a, double b){ //构造函数 x = a; y = b; } double distance(Point p){ //计算两点之间的距离 return sqrt(pow(x-p.x,2)+pow(y-p.y,2)); } };

int main(){ Point p1(3.0, 4.0); Point p2(5.0, 6.0); double dis = p1.distance(p2); //计算距离 cout << "The distance is " << dis << endl; system("pause"); return 0; }

根据提示设计类Point如下使用友员计算两点p13040、p25060之间的距离并在主函数中调用输出运行结果如下The distance is 14Press any key to contine

原文地址: https://www.cveoy.top/t/topic/hoW4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录