请教C++语言

来源:百度知道 编辑:UC知道 时间:2024/06/06 13:05:05
请设计一个盒子类Box,它具有:
私有数据成员:
长度(length),宽度(width),高度(height);
公有成员函数:
求盒子的体积函数volume ( );
显示盒子的长度、宽度、高度信息的函数display();
要求:不仅要写出类的声明,还要写出成员函数的代码(类外定义方式)。

二楼编的什么东西,懂类吗?!!

class box
{
private:
float length,width,height;
public:
box(float len,float wid,float hei)
{
this->length=len;
this->width=wid;
this->height=hei;
}
double volume();
void display();
};

double box::volume()
{
return length*width*height;
}

void box::display()
{
cout<<"length="<<length<<endl;
cout<<"width="<<width<<endl;
cout<<"height="<<height<<endl;
}

10分少了点把

class Box
{
private int:length,width,height;
public Box(int length,int width,int height)
{
this.length=length;
this.width=width;
this.height=height;
}
public int volume()
{
return length*width*height;
}
public void display()
{
cout<<length<&