1 #include <iostream> 2 using namespace std; 3 class Box{ 4 private: 5 double length; 6 double width; 7 public: 8 void setLength(double length); 9 void setWidth(double width); 10 double getLength(); 11 double getWidth(); 12 double getArea(); 13 }; 14 void Box::setLength(double length){ 15 this->length = length; 16 } 17 void Box::setWidth(double width){ 18 this->width =width; 19 } 20 double Box::getArea(){ 21 return length*width; 22 } 23 double Box::getLength(){ 24 return length; 25 } 26 double Box::getWidth(){ 27 return width; 28 } 29 int main(){ 30 Box box; 31 box.setLength(6.0); 32 box.setWidth(7.0); 33 cout<<box.getArea()<<endl; 34 return 0; 35 }
标签:Box,box,double,void,width,length,class From: https://www.cnblogs.com/liujiaxing-/p/17991086