hw5-2.cpp

来自「学习c++的ppt」· C++ 代码 · 共 22 行

CPP
22
字号
#include <iostream.h>
#include <math.h>

class Point {
	    float x, y;
	public:
		Point(float xx, float yy)  {
			x = xx; y = yy;
		}
		friend float Distance(Point &, Point &);
};
float Distance(Point &p1, Point &p2)  {
	float dx, dy;
	dx = p2.x - p1.x;
	dy = p2.y - p1.y;
	return (float)sqrt(dx * dx + dy * dy);
}
void main()  {
    Point s(10, 10), t(25, 30);
	cout << "两点之间距离为:" << Distance(s, t) << endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?