//A more complex Rectangle class: added increase, perimeter and area #include #include #include using namespace std; //Rectangle class declaration class Rectangle { private: double width; double length; public: Rectangle(); //constructor Rectangle(double, double); //constructor void setWidth(double); void setLength(double); double getWidth() const; double getLength() const; double area() const; bool square() const; string toString() const; void increase(); //increase length and width by one void increase(double); //increase length and width by an amount double perimeter() const; double diagonal() const; }; Rectangle::Rectangle() { width=1; length=1; } //constructor Rectangle::Rectangle(double w, double l) { if(w>0) width=w; if(l>0) length=l; } //constructor void Rectangle::setWidth(double w) { if(w>0) width=w; //by making width private we can make sure that is >0 } //setWidth void Rectangle::setLength(double l) { if(l>0) length=l; } //setLength double Rectangle::getWidth() const { return width; } //getWidth double Rectangle:: getLength() const { return length; } //getWidth double Rectangle::area() const{ return width*length; } //getArea bool Rectangle::square() const{ return width==length; } //square string Rectangle::toString() const { std::ostringstream oss; //a stream to append the values oss<0) { width+=amount; length+=amount; }//if } //increase by amount double Rectangle::perimeter() const { return (width+length)*2; }//perimeter double Rectangle::diagonal() const { return sqrt(width*width+length*length); } //diagonal int main() { Rectangle box; //box is an instance of Rectangle class box.setWidth(5); //set member attribute width box.setLength(8); //set member attribute length Rectangle crate; //crate is an instance of Rectangle class 1x1 Rectangle carton(3,6); //carton is declared using constructor 3x6 Rectangle myBox; double wdth, lnth; cout<<"Enter width of rectangle:"; cin>>wdth; myBox.setWidth(wdth); if(myBox.getWidth()!=wdth) cout<<"The value "<>lnth; myBox.setLength(lnth); cout<