题解 | 设计立方体类

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

全部评论

相关推荐

点赞 评论 收藏
分享
05-12 17:00
门头沟学院 Java
king122:你的项目描述至少要分点呀,要实习的话,你的描述可以使用什么技术,实现了什么难点,达成了哪些数字指标,这个数字指标尽量是真实的,这样面试应该会多很多,就这样自己包装一下,包装不好可以找我,我有几个大厂最近做过的实习项目也可以包装一下
点赞 评论 收藏
分享
认真搞学习:28小登的建议,投算法岗不要写什么物理竞赛,互联网+,多写点项目,用什么算法做了什么。还有本科算法是不可能的开发你这个也没有项目啊
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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