C++_拷贝构造函数练习_已知两点的坐标,求两点的距离

在做数学建模,需要求出图像上两个像素点的距离,代码如下:

#include  
#include  
#include
using namespace std;class Point {
private:double x, y;
public:Point(double x, double y){this->x = x;this->y = y;}double Getx(){return x;}double Gety(){return y;}double Distance(const Point &p)  //定义拷贝构造函数  {x -= p.x;y -= p.y;return sqrt(x*x + y * y);}void ShowPoint(){cout << "<" << Getx() << "," << Gety() << ">" << endl;}
};int main()
{double x1, y1, x2, y2;double dis;x1 = 522;x2 = 699;y1 = 751;y2 = 669;Point P1(x1, y1);Point P2(x2, y2);dis = P1.Distance(P2);cout.precision(2);cout.setf(ios::fixed);cout<<"a,b两点的距离是:" << dis << endl;system("pause");return 0;}

在这里插入图片描述


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部