创建一个长方体类,数据成员至少包括长、宽、高,分别命名为length width height.要求用成员函数完成如下功能:
(1)从键盘上输入长、宽、高。
(2)计算长方体的体积与表面积。
(3)输出长方体的体积与表面积。
例:
1.1 2.2 3.3
area=26.62,volume=7.986
请注意;main()函数必须按如下所示编写:
int main()
{
Cuboid cc; float a,b,c;
cin>>a>b>c;
cc. set value(a,b,c);
cc. count area();
cc. count volume();
cc. show();
return 0;
}
#include<iostream>
using namespace std;
class Cuboid
{
public:
void setvalue(float a, float b, float c)
{
this->length = a;
this->width = b;
this->height = c;
}
void countarea()
{
this->area = 2 * (this->height*this->length + this->height*this->width + this->length*this->width);
}
void countvolume()
{
this->volume = this->height*this->length*this->width;
}
void show()
{
cout << "area=" << this->area << "," << "volume=" << this->volume;
}
private:
float length;
float width;
float height;
float area;
float volume;
};
int main()
{
Cuboid cc; float a, b, c;
cin >> a >> b >> c;
cc.setvalue(a, b, c);
cc.countarea();
cc.countvolume();
cc.show();
return 0;
}