早教吧 育儿知识 作业答案 考试题库 百科 知识分享

C++题目计算3个长方体体积#includeusingnamespacestd;classBox{private:floatlength;floatwidth;floatheight;public:Box(floatl,floatw,floath);Input();Count();};Box::Box(floatl,floatw,floath){length=l;width=w;height=h;}Box

题目详情
C++题目 计算3个长方体体积
#include
using namespace std;
class Box
{
private:
float length;
float width;
float height;
public:
Box(float l,float w,float h);
Input();
Count();

};
Box::Box(float l,float w,float h)
{ length=l;
width=w;
height=h;
}
Box::Input()
{cin>>length>>width>>height;
}
Box::Count()
{
return length*width*height;

}
int main()
{ Box b1,b2,b3;
cout
▼优质解答
答案和解析
#include
using namespace std;
class Box
{
private:
float length;
float width;
float height;
public:
Box (float l, float w, float h);
void Input(); // 需要返回类型
float Count(); // 需要返回值
};
Box::Box (float l, float w, float h)
{
length = l;
width = w;
height = h;
}
void Box::Input() // 需要返回类型
{
cin >> length >> width >> height;
}
float Box::Count() // 需要返回值
{
return length * width * height;
}
int main()
{
Box b1(1, 2, 3); // 构造器需要参数
Box b2(2, 2, 2);
Box b3(3, 2, 1);
cout