题解 | 设计立方体类

设计立方体类

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

#include <iostream>
using namespace std;

class Cube {
    private:
        int length;
        int width;
        int height;
    public:
        Cube(){}
        int getArea(){
            return 2*(length*width+width*height+length*height);
        };
        int getVolume(){
            return length*width*height;
        };
        int setLength(int l){
            return length = l;
        };
        int setWidth(int w){
            return width = w;
        };
        int setHeight(int h){
            return height = h;
        }; 
        int getLength(){
            return length;
        };
        int getWidth(){
            return width;
        };
        int getHeight(){
            return height;
        };                          

    // write your code here......
    

};

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;
}

C/C++题解 文章被收录于专栏

记录个人编程题的解题思路以及学习的新知识

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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