需要求三个长方体的体积,请编写一个基于对象的程序
10-28
需要求三个长方体的体积,请编写一个基于对象的程序。数据包括length,width,height,要求用成员函数实现以下功能
1、由键盘输入3个长方体长、宽、高
2、计算长方体的体积
3、输出3个长方体的体积
源程序:
#include
class cuboid
{
public:void set_cuboid();
void show_cuboid();
private:double length;
double width;
double height;
double cuboid1;
};
void cuboid::set_cuboid()
{
cout
cin>>length>>width>>height;
}
void cuboid::show_cuboid()
{
cuboid1=length*width*height;
cout
}
int main()
{
cuboid cuboid2,cuboid3,cuboid4;
cuboid2.set_cuboid();
cuboid2.show_cuboid();
cuboid3.set_cuboid();
cuboid3.show_cuboid();
cuboid4.set_cuboid();
cuboid4.show_cuboid();
return 0;
}