#include<iostream>
using namespace std;
class Box
{
private:
double x;
double y;
double z;
public:
Box()
{
this->x = 1;
this->y = 1;
this->z = 1;
}
Box(double x, double y, double z)
{
this->x = x;
this->y = y;
this->z = z;
}
void getv()
{
double v = x * y * z;
cout << "体积是:" << v << endl;
}
void gets()
{
double s = x * y + x * z + y * z;
cout << "表面积是:" << 2 * s << endl;
}
};
int main()
{
double a, b, c;
cin >> a >> b >> c;
Box v1(a, b, c);
v1.gets();
v1.getv();
return 0;
}
该程序定义了一个Box类,用于表示三维矩形箱子,并实现了计算其体积和表面积的方法。在main函数中,用户输入箱子的三个边长,然后创建Box对象并输出其表面积和体积。
1744

被折叠的 条评论
为什么被折叠?



