程序是用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="<
};
void main()
{
float l,w,h;
cout<<"请输入盒子的长度:"<
cout<<"请输入盒子的宽度:"<
cout<<"请输入盒子的高度:"<
Box m_box(l,w,h);
m_box.disp();
}