题解 | #设计立方体类#

设计立方体类

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

#include <iostream>
using namespace std;

class Cube {

    // write your code here......
   private:
   int length = 0;
   int width =0;
   int height =0;
   public:
   void setLength(int a);
   void setWidth(int a);
   void setHeight(int a);
   int getLength();
   int getWidth();
   int getHeight();
   int getArea();
   int getVolume(); 

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




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-03 12:09
東京大学 C++
点赞 评论 收藏
分享
05-07 20:52
吉林大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务