先创建一个类,再在里面构造函数
class Cuboid//创建长方体类
{
private://定义了三个私有变量
double length;//长
double width;//宽
double height;//高
public:
double getCu()
{
return length, width, height;//返回长宽高
}
void setCu(double length, double width, double height)//函数获取参数
{
this->length = length;
this->width = width;
this->height = height;
cout << endl;
}
double calCuV(double length, double width, double height)
{
double cal = length * width*height;
cout << "长方体的体积V是:" << cal;
cout << endl;
return cal;//返回值是体积底面积*高
}
//构造函数
//01.无参
Cuboid() { double length = 0; double width = 0; double height=0;}
//02.有参
Cuboid(double length, double width, double height)
{
this->length = length;
this->width = width;
this->height = height;
}
Cuboid(Cuboid&c)
{
this->length = c.height;
this->width = c.width;
this->height = c.width;
}
};
函数内容细化放在类里面比较明了简洁也可以放在类外面创建类函数
创

最低0.47元/天 解锁文章
3291





