#include<iostream> using namespace std; #include<string> class Cube { public: void setH(int H)//设置高 { m_H = H; } int getH()//获取高 { return m_H; } void setW(int W)//设置宽 { m_W = W; } int getW()//获取宽 { return m_W; } void setL(int L)//设置长 { m_L = L; } int getL()//获取长 { return m_L; } int caculateS() { return 2 * m_L * m_W + 2 * m_L * m_H + 2 * m_W * m_H; } int caculateV() { return m_L * m_W * m_H; } private: int m_L;//长 int m_W;//宽 int m_H;//高 }; int main() { //创建立方体对象 Cube c1; c1.setH(10); c1.setL(10); c1.setW(10); cout << "立方体的面积:" << c1.caculateS() << endl; cout << "立方体的体积:" << c1.caculateV() << endl; system("pause"); return 0; }