题解 | #设计立方体类#

设计立方体类

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

#include <iostream>
using namespace std;

class Cube {

    // write your code here......
public:
    int length;
    int width;
    int height;

    int getArea(){
        return 2*length*width+2*length*height+2*width*height;
    }

    int getVolume(){
        return length*width*height;
    }
    void setHeight(int height){
        this->height = height;
    }
    int getHeight(){
        return height;
    }
    void setLength(int length){
        this->length = length;
    }
    int getLength(){
        return length;
    }

    void setWidth(int width){
        this->width = width;
    }
    int getWidth(){
        return width;
    }
};

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

全部评论

相关推荐

躺尸修仙中:因为很多92的也去卷中小厂,反正投递简历不要钱,面试不要钱,时间冲突就推,不冲突就面试积累经验
点赞 评论 收藏
分享
09-29 17:44
已编辑
蔚来_测(准入职员工)
//鲨鱼辣椒:见不了了我实习了四个月上周再投筛选了一天就给我挂了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务