定义一个表示三维空间坐标点的类,并对“>”运算符重载,如果A点到原点的距离大于B点到原点的距离,则A>B为

真,否则为假。用C++编写... 真,否则为假。用C++编写 展开
 我来答
guanyayang
2010-12-18 · TA获得超过1134个赞
知道小有建树答主
回答量:377
采纳率:0%
帮助的人:295万
展开全部
#include <iostream>
#include <math.h>
using namespace std;
class Points
{
private:
double x;
double y;
double z;
public:
Points(){x=0.0;y=0.0;z=0.0;}
Points(double x,double y,double z)
{
this->x=x;
this->y=y;
this->z=z;
}
bool operator>(Points &a)
{
return sqrt(pow(this->x,2)+pow(this->y,2)+pow(this->z,2))>sqrt(pow(a.x,2)+pow(a.y,2)+pow(a.z,2));
}
};
int main()
{
Points a(1.0,2.0,3.0);
Points b(3.0,4.0,5.0);
bool k=a>b;
cout<<k;
return 0;
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式