#include <iostream> using namespace std; class Box{ private: double length; double width; public: void setLength(double length); void setWidth(double width); double getLength(); double getWidth(); double getArea(); }; void Box::setLength(double length){ this->length=length; } void Box::setWidth(double width){ this->width=width; } double Box::getArea(){ return length*width; } double Box::getLength(){ return length; } double Box::getWidth(){ return width; } int main(){ Box box; box.setLength(6.0); box.setWidth(7.0); cout<<box.getArea()<<endl; return 0; }
标签:Box,示例,--,double,代码,width,length,setWidth,void From: https://www.cnblogs.com/fushuxuan/p/17991088