c++:建立一个类cylinder,cylinder的构造函数被传递了两个double值,分别表示圆柱体的半径和高度,
来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/06/06 09:18:49
c++:建立一个类cylinder,cylinder的构造函数被传递了两个double值,分别表示圆柱体的半径和高度,
用类cylinder 计算圆柱体的体积,并存储在一个double变量中,并在cylinder中包含一个成员函数vol(),来显示每个对象的体积.
1,建立一个静态成员 static int total_vol;累加体积
2,建立一个cylinder 的友元函数用来获取它的私有数据
3,main函数中建立三个类,cylinder的对象,并用静态成员完成累加,友元显示数据.
下面三点是附加要求,得一并写在程序中,麻烦你们了.
用类cylinder 计算圆柱体的体积,并存储在一个double变量中,并在cylinder中包含一个成员函数vol(),来显示每个对象的体积.
1,建立一个静态成员 static int total_vol;累加体积
2,建立一个cylinder 的友元函数用来获取它的私有数据
3,main函数中建立三个类,cylinder的对象,并用静态成员完成累加,友元显示数据.
下面三点是附加要求,得一并写在程序中,麻烦你们了.
#include
using namespace std;
#define PI 3.14159
class Cylinder{
public:
Cylinder(double radius,double height):radius(radius),height(height),volume(PI*radius*radius*height){
total_vol += volume;
}
double vol()const;
friend void getParas(double& radius,double&height,double&vol,double& total_vol,const Cylinder& obj);
private:
double radius; //radius
double height; //height
double volume;//volume of current object
static double total_vol;//total volume
};
double Cylinder::total_vol = 0;
double Cylinder::vol()const{
return this->volume;
}
void getParas(double& radius,double& height,double& vol,double& total_vol,const Cylinder& obj){ //get private member of Cylinder
radius = obj.radius;
height = obj.height;
vol = obj.volume;
total_vol = obj.total_vol;
}
int main(){
double rd = 0,hg = 0,vol = 0,total_vol = 0;
Cylinder cld_1(2,3.5),cld_2(5.2,7),cld_3(3.9,4.0);//3 objects
getParas(rd,hg,vol,total_vol,cld_3);
cout
using namespace std;
#define PI 3.14159
class Cylinder{
public:
Cylinder(double radius,double height):radius(radius),height(height),volume(PI*radius*radius*height){
total_vol += volume;
}
double vol()const;
friend void getParas(double& radius,double&height,double&vol,double& total_vol,const Cylinder& obj);
private:
double radius; //radius
double height; //height
double volume;//volume of current object
static double total_vol;//total volume
};
double Cylinder::total_vol = 0;
double Cylinder::vol()const{
return this->volume;
}
void getParas(double& radius,double& height,double& vol,double& total_vol,const Cylinder& obj){ //get private member of Cylinder
radius = obj.radius;
height = obj.height;
vol = obj.volume;
total_vol = obj.total_vol;
}
int main(){
double rd = 0,hg = 0,vol = 0,total_vol = 0;
Cylinder cld_1(2,3.5),cld_2(5.2,7),cld_3(3.9,4.0);//3 objects
getParas(rd,hg,vol,total_vol,cld_3);
cout
c++:建立一个类cylinder,cylinder的构造函数被传递了两个double值,分别表示圆柱体的半径和高度,
这是一个考题,建立类box,box的构造函数被传递了3个double值,每一个double值表示盒子的一条边长.用BOX
java编程求高手 2.定义类Shape和子类Circle、Cylinder.定义类的无参构造函数和有参构造函数,并增加
定义并实现类Circle(圆)和(Cylinder)圆柱体,Cylinder公用派生自Circle类.急!
1. 编一个使用派生类的程序求圆柱体(Cylinder)的体积.设计一个圆类(Circle)和一个矩形类(Rectang
cylinder
如何在ANSYS中建立一个实体圆柱模型啊,为什么我通过Solid Cylinder中建立出的是一个圆呢,半径25,高50
定义一个描述圆形的类,类中有两个成员变量:R,Area,分别表示圆的半径和面积.定义构造函数,初始化这两个变量;定义方法
Matlab cylinder 函数
有高度相等的A、B两个圆柱体容器.从里面量半径分别为8厘米和10厘米.
pheumatic cylinder
定义Point,Circle,Cylinder类.用友元求(friend)圆面积,圆柱体体积.