题解 | 设计立方体类

#include <iostream>
#include <type_traits>
using namespace std;

class Cube {

    // write your code here......
private:
    int length_;
    int width_;
    int height_;
public:
    void setLength(const int& length){
        length_ = length;
    }
    void setWidth(const int& width){
        width_ = width;
    }
    void setHeight(const int& height){
        height_ = height;
    }

    int getLength(){
        return length_;
    }
    int getWidth(){
        return width_;
    }
    int getHeight(){
        return height_;
    }

    int getArea(){
        return 2*length_*width_ + 2*length_*height_ + 2*width_*height_;
    }
    int getVolume(){
        return length_*width_*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;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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