题解 | #设计立方体类#

设计立方体类

https://www.nowcoder.com/practice/0f02d35dcd564f0a87865d604eccbe18

#include <iostream>
using namespace std;

class Cube {

    // write your code here......
    int m_length;
    int m_width;
    int m_height;
public:
    void setLength(int length);
    void setWidth(int width);
    void setHeight(int height);
    
    int getLength();
    int getWidth();
    int getHeight();
    int getArea();
    int getVolume();
};

void Cube::setLength(int length) {   m_length = length;   }
void Cube::setWidth(int width)   {   m_width = width;     }
void Cube::setHeight(int height) {   m_height = height;   }
    
int Cube::getLength()   {   return m_length;    }
int Cube::getWidth()    {   return m_width;     }
int Cube::getHeight()   {   return m_height;    }
int Cube::getArea()     {   return 2*(m_length*m_width+m_length*m_height+m_width*m_height);    }
int Cube::getVolume()   {   return m_length*m_width*m_height;}

int main() {

    int length, width, height;
    cin >> length;
    cin >> width;
    cin >> height;

    Cube c;
    c.setLength(length);
    c.setWidth(width);
    c.setHeight(height);

    cout << c.getLength() << " "
        << c.getWidth() << " "
        << c.getHeight() << " "
        << c.getArea() << " "
        << c.getVolume() << endl;

    return 0;
}

全部评论

相关推荐

04-25 18:13
五邑大学 Java
后来123321:大二两段实习太厉害了,我现在大二连面试都没有
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务