1  #include "DerivedRectangle.h"
  2  
  3  // Construct a default rectangle object
  4  Rectangle::Rectangle()
  5  {
  6    width = 1;
  7    height = 1;
  8  }
  9  
 10  // Construct a rectangle object with specified width and height
 11  Rectangle::Rectangle(double width, double height)
 12  {
 13    setWidth(width);
 14    setHeight(height);
 15  }
 16  
 17  Rectangle::Rectangle(
 18    double width, double height, const string& color, bool filled)
 19  {
 20    setWidth(width);
 21    setHeight(height);
 22    setColor(color);
 23    setFilled(filled);
 24  }
 25  
 26  // Return the width of this rectangle
 27  double Rectangle::getWidth() const
 28  {
 29    return width;
 30  }
 31  
 32  // Set a new radius
 33  void Rectangle::setWidth(double width)
 34  {
 35    this->width = (width >= 0) ? width : 0;
 36  }
 37  
 38  // Return the height of this rectangle
 39  double Rectangle::getHeight() const
 40  {
 41    return height;
 42  }
 43  
 44  // Set a new height
 45  void Rectangle::setHeight(double height)
 46  {
 47    this->height = (height >= 0) ? height : 0;
 48  }
 49  
 50  // Return the area of this rectangle
 51  double Rectangle::getArea() const
 52  {
 53    return width * height;
 54  }
 55  
 56  // Return the perimeter of this rectangle
 57  double Rectangle::getPerimeter() const
 58  {
 59    return 2 * (width + height);
 60  }
 61  
 62  // Redefine the toString function, to be covered in Section 15.5
 63  string Rectangle::toString() const
 64  {
 65    return "Rectangle object";
 66  }