设立一个立方体类Box,在该类定义中包括

2025-03-04 18:47:15
推荐回答(1个)
回答1:

程序是用VC++6.0写的,你看看吧,希望对你有用。
#include

class Box{
float length,width,height;
public:
Box(float len=1,float wid=1,float hei=1)
{
length=len;
width=wid;
height=hei;
}
float volume()
{
float v;
v=length*width*height;
return v;
}
float area()
{
float ar;
ar=2*(length*width+length*height+width*height);
return ar;
}
void disp()
{
cout<<"Volume="< cout<<"Area="< }
};

void main()
{
float l,w,h;
cout<<"请输入盒子的长度:"< cin>>l;
cout<<"请输入盒子的宽度:"< cin>>w;
cout<<"请输入盒子的高度:"< cin>>h;
Box m_box(l,w,h);
m_box.disp();
}