题解 | #设计立方体类#
设计立方体类
https://www.nowcoder.com/practice/0f02d35dcd564f0a87865d604eccbe18
#include <iostream> #include <pthread.h> using namespace std; class Cube { public: Cube(int l,int w,int h); int getArea(int l,int w,int h); int getVolume(int l,int w,int h); private: int length,width,height; }; Cube::Cube(int l,int w,int h) { length=l; width=w; height=h; } int Cube::getArea(int l,int w,int h) { return 2*l*h+2*l*w+2*w*h; } int Cube::getVolume(int l,int w,int h) { return length*width*height; } int main() { int l; int w; int h; cin>>l>>w>>h; Cube cube(l,w,h); cout<<l<<" "<<w<<" "<<h<<" "<<cube.getArea(l,w,h)<<" "<<cube.getVolume(l,w,h)<<endl; return 0; }