还要求能计算面积,至少写个模型给我。满意,给200.谢谢。
说错了,是计算体积。
用C++面向对象写个球体的类,要调用另外一个Point的类,就是组合类。
答案:2 悬赏:10 手机版
解决时间 2021-03-22 04:14
- 提问者网友:鼻尖触碰
- 2021-03-21 07:17
最佳答案
- 五星知识达人网友:走死在岁月里
- 2021-03-21 07:57
#include
#include
#define PI 3.14
using namespace std;
class Point
{
double x,y;
public:
Point(){
}
Point(Point& p)//拷贝构造函数
{
this->x=p.x;
this->y=p.y;
}
Point& operator=(const Point& p)//赋值构造函数
{
this->x=p.x;
this->y=p.y;
}
Point(double x,double y) //构造函数
{
this->x=x;
this->y=y;
}
double distanceOfPoint(const Point& p) //计算两点间距离
{
return sqrt((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y));
}
void setPoint(double x,double y) //改变坐标,不实用
{
this->x=x;
this->y=y;
}
};
class Orb
{
Point p;
double r;
public:
Orb(double r,Point p)
{
this->r=r;
this->p=p;
}
double getVolume() //计算体积
{
return 4/3*PI*r*r;
}
void setCenterPoint(const Point&p)//设置圆心
{
this->p=p;
}
void setR(double r)//设置半径
{
this->r=r;
}
};
int main()
{
double r=4;
Point center(3,3);
Orb o(r,center);
double volume=o.getVolume();
cout<<"半径为:"<
}
#include
#define PI 3.14
using namespace std;
class Point
{
double x,y;
public:
Point(){
}
Point(Point& p)//拷贝构造函数
{
this->x=p.x;
this->y=p.y;
}
Point& operator=(const Point& p)//赋值构造函数
{
this->x=p.x;
this->y=p.y;
}
Point(double x,double y) //构造函数
{
this->x=x;
this->y=y;
}
double distanceOfPoint(const Point& p) //计算两点间距离
{
return sqrt((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y));
}
void setPoint(double x,double y) //改变坐标,不实用
{
this->x=x;
this->y=y;
}
};
class Orb
{
Point p;
double r;
public:
Orb(double r,Point p)
{
this->r=r;
this->p=p;
}
double getVolume() //计算体积
{
return 4/3*PI*r*r;
}
void setCenterPoint(const Point&p)//设置圆心
{
this->p=p;
}
void setR(double r)//设置半径
{
this->r=r;
}
};
int main()
{
double r=4;
Point center(3,3);
Orb o(r,center);
double volume=o.getVolume();
cout<<"半径为:"<
}
全部回答
- 1楼网友:舊物识亽
- 2021-03-21 08:25
虽然我很聪明,但这么说真的难到我了
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯