6_52.cpp

来自「C++程序设计技能百练随书配套光盘的源码」· C++ 代码 · 共 42 行

CPP
42
字号
#include<iostream.h>
#include<math.h>
class Point
{
public:
	void SetPoint();
	double Distance();
private:
	double X1,Y1,X2,Y2;
};

void Point::SetPoint()
{
	double x1,y1,x2,y2;
	cout<<"Input the first point's coordinate!"<<endl;
	cout<<"x1=";
	cin>>x1;
	cout<<"y1=";
	cin>>y1;
	cout<<endl;
	cout<<"Input the second point's coordinate!"<<endl;
	cout<<"x2=";
	cin>>x2;
	cout<<"y2=";
	cin>>y2;
	X1=x1;Y1=y1;X2=x2;Y2=y2;
}
double Point::Distance()
{
	double distance;
	distance=sqrt((X1-X2)*(X1-X2)+(Y1-Y2)*(Y1-Y2));
	return distance;
}

void main()
{
	Point mypoint;
	mypoint.SetPoint();
	cout<<"The distance of the two points is:"<<mypoint.Distance();
	cout<<endl;
}

⌨️ 快捷键说明

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