l6_5.cpp

来自「《C++程序设计教程》电子教案及例题源码」· C++ 代码 · 共 43 行

CPP
43
字号
#include <iostream.h>
#include <math.h>
class CPoint
{
public:
	CPoint(int x=0, int y=0);
	int GetX();
	int GetY();
	friend double GetDistance(CPoint start, CPoint end);
private:
	int X,Y;
};

CPoint::CPoint(int x, int y)
{
	X=x;
	Y=y;
};
int CPoint::GetX()
{
	return X;
}
int CPoint::GetY()
{
	return Y;
}

double GetDistance(CPoint start, CPoint end)
{
	double d;
	d = sqrt( (end.X-start.X)*(end.X-start.X) + (end.Y-start.Y)*(end.Y-start.Y) );
	return d;
}

void main()
{
    CPoint p1(1,1), p2(4,5);
	double d;
	d = GetDistance(p1,p2);
	cout << "The distance is :" << d << endl;
}

⌨️ 快捷键说明

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