c++ 设计一个立方体的类,求出立方体的面积和体积
#include<iostream>using namespace std;/*设计一个立方体的类,求出立方体的面积和体积*/class Cube{public://求出立方体的面积和体积int cal_cube_S(int h,intw, int l){int c_H = h; int c_W = w; int c_L = l;int c_S;c_S = c_H * c_W * 2
·
#include<iostream>
using namespace std;
/*
设计一个立方体的类,求出立方体的面积和体积
*/
class Cube
{
public:
//求出立方体的面积和体积
int cal_cube_S(int h,int w, int l)
{
int c_H = h; int c_W = w; int c_L = l;
int c_S;
c_S = c_H * c_W * 2 + c_L * c_W * 2 + c_H * c_L * 2;
return c_S;
}
int cal_cube_V(int h, int w, int l)
{
int c_H = h; int c_W = w; int c_L = l;
int c_S, c_V;
c_V = c_H * c_W * c_L;
return c_V;
}
void print(int h, int w, int l, int S, int V)
{
cout << "长:" << l << " 宽:" << w << " 高:" << h << endl;
cout << "表面积:" << S << endl;
cout << "体积:" << V << endl;
}
private:
int c_H, c_W, c_L;
};
int main()
{
int l1=10, w1=10, h1=10;
int l2 = 10, w2 = 10, h2 = 10;
Cube cube;
int S1=cube.cal_cube_S(l1,w1,h1);
int V1 = cube.cal_cube_V(l1, w1, h1);
int S2 = cube.cal_cube_S(l2, w2, h2);
int V2=cube.cal_cube_V(100, 10, 10);
cube.print(h1, w1, l1, S1, V1);
cube.print(h2, w2, l2, S2, V2);
system("pause");
return 0;
}
更多推荐
所有评论(0)