我吃辣条女主角沈佳妮:跪地求一道C++题目的答案????高手就帮帮我吧!

来源:百度文库 编辑:神马品牌网 时间:2024/05/04 08:41:58
定义一个Box(盒子)类,在该类定义中包括
数据成员:length(长);width(宽)和height(高).
成员函数:构造函数Box设置盒子长宽高三个初始数据;函数volume计算并输出盒子的体积。在main函数中,要求创建Box对象,并求盒子的体积

#include<iostream.h>
class box
{
private: int length; int width; int height;
public: box(void)
{
length=10; width=10; height=10;
}
friend int volume(box h);
};
int volume(box h)
{
return(h.height*h.length*h.width);
}
void main()
{
box cube;

cout<<"volume="<<volume(cube)<<endl;
}

Class Box
{
public:
double Volume()
{
return (length * width * height);
}
Box(double l, double w, double h):leghth(0.0),width(0.0),height(0.0)
{
length = l;
width = w;
height = h;
}
double length;
double width;
double height;
}

int main()
{
Box bb(1.1, 2.2, 3.3);
cout << bb.Volume()<<endl;
}