题解 | #设计立方体类#
设计立方体类
https://www.nowcoder.com/practice/0f02d35dcd564f0a87865d604eccbe18
#include <iostream> using namespace std; class Cube { // write your code here...... int m_length; int m_width; int m_height; public: void setLength(int length); void setWidth(int width); void setHeight(int height); int getLength(); int getWidth(); int getHeight(); int getArea(); int getVolume(); }; void Cube::setLength(int length) { m_length = length; } void Cube::setWidth(int width) { m_width = width; } void Cube::setHeight(int height) { m_height = height; } int Cube::getLength() { return m_length; } int Cube::getWidth() { return m_width; } int Cube::getHeight() { return m_height; } int Cube::getArea() { return 2*(m_length*m_width+m_length*m_height+m_width*m_height); } int Cube::getVolume() { return m_length*m_width*m_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; }