定义一个Point类并用成员函数 double Distance(const& Point)求两点间距离
#include
#include
using namespace std;
class Point
{
private:
double X,Y;
public:
Point(double x,double y)
{
X=x;
Y=y;
}//构造函数
double GetX()
{
return X;
}
double GetY()
{
return Y;
}
double Distance(const& Point)
{ double d;
return d=sqrt((Point.X-X)*(Point.X-X)+(Point.Y-Y)*(Point.Y-Y));
}
void show()
{
cout
人气:310 ℃ 时间:2020-06-18 19:07:50
解答
#include
#include
using namespace std;
class Point
{
private:
double X,Y;
public:
Point(double x,double y)
{
X=x;
Y=y;
}//构造函数
double GetX()
{
return X;
}
double GetY()
{
return Y;
}
double Distance(const Point &p) //传入对象引用
{
return sqrt((X-p.X)*(X-p.X)+(Y-p.Y)*(Y-p.Y));
}
void show(const Point &p)
{
cout
推荐
- 定义一个点类(Point),其数据成员包含横坐标和纵坐标;再定义一个距离类(Distance),用于描述两点之间
- 4.可以定义点类(Point),再定义一个类(Distance)描述两点之间的距离,其数据成员为两个点类对象,两点
- 首先定义一个点类 POINT ,有两个 double 型的 保护 数据成员 x ,y 表示该类对象在二维坐标系中的坐标位
- 用C/C++定义一个点类Point/
- 定义Point类
- 范仲淹在《渔家傲》一词中,揭示自己和征夫们想家却不甘无功而返的矛盾心理的句子.
- 形容音乐或音质非常美好的词语,2—4个字,
- 谁能给我一张英文的结婚请柬?
猜你喜欢