题解 | #利用指针遍历数组#
设计立方体类
http://www.nowcoder.com/practice/0f02d35dcd564f0a87865d604eccbe18
#include using namespace std;
class Cube { public: void setLength(int length) { m_length=length; } void setWidth(int width) { m_width=width; } void setHeight(int height) { m_height=height; } int getLength() { return m_length; } int getWidth() { return m_width; } int getHeight() { return m_height; } int getArea() { return 2m_lengthm_width+2m_lengthm_height+2m_widthm_height; } int getVolume() { return m_widthm_lengthm_height; } // write your code here...... private: int m_length; int m_width; int 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;
}