您的位置:首页 > 编程语言 > C语言/C++

C++ 用类实现point 两点的距离

2016-09-04 22:56 218 查看
最近看了下欧丽奇《程序员面试宝典》,看到有个列子很好,就敲下来分给大家

#include "stdafx.h"

#include <iostream>

using namespace std;

class point

{

float x, y;

public:

point(float a = 0.0f, float b = 0.0f) : x(a),y(b){};

friend float danstence(point left, point right);

};

float danstence(point left, point right)

{

return sqrt(((left.x - right.x)*(left.x - right.x) + (left.y - right.y)*(left.y - right.y)));

}

void main()

{

point tmp1(0,0);

point tmp2(3,4);

danstence(tmp1, tmp2);

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐