title: How to use classes to create rectangles
body: <p>I need to create a program that uses a class to create three triangles from user input, including the following specifications:</p>
  
  <ol>
  <li><p>The private data shall consist of 4 members:
  length
  width
  area
  perimeter</p></li>
  <li><p>Have 1 constructor with the following parameters: length and width.</p></li>
  <li><p>Have 2 mutators:
  setLength  to set/modify the length
  and setWidth to set/modify the width.</p></li>
  <li><p>Have 5 accessors:
  getLength to return the length</p>
  
  <p>getWidth to return the width</p>
  
  <p>getPerimeter to return the perimeter</p>
  
  <p>getArea to return the area</p>
  
  <p>printObjet to print the representation of the rectangle (using the same 
  output criteria of the previous incarnations)</p></li>
  </ol>
  
  <p>For extra credit Store 10 rectangle objects you created in a vector and sequence through the vector to print out the 10 rectangle objects. Once I get how to do the main assignment I believe I can do this on my own, though extra help wouldn't go amiss.</p>
  
  <p>After editing with the changes from DimChtz the code is below.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  // Rectangle class declaration.
  class Rectangle
  {
     private:
        double width;
        double length;
        double area;
        double perimeter;
  
  
     public:
        void setWidth(double);
        void setLength(double);
        double getWidth();
        double getLength();
        double getArea();
        double getPerimeter();
        void printObjet();
        void calc();
        Rectangle();
  };
  
  //beginning class constructor
  Rectangle::Rectangle() {
      this-&gt;width = 0;
      this-&gt;length = 0;
      this-&gt;area = 0;
      this-&gt;perimeter = 0;
  }
  // main class constructor
  Rectangle::Rectangle(double width, double length)
  {   this-&gt;width = width;
      this-&gt;length = length;
      this-&gt;calc();
  }
  //calc calculates the area and perimeter from width and length.
  void Rectangle::calc() {
      this-&gt;area = this-&gt;width * this-&gt;length;
      this-&gt;perimeter = 2 * (this-&gt;width + this-&gt;length); }
  
  // the class functions definition
  // setWidth assigns its argument to the private member width.
  void Rectangle::setWidth(double width)
  {   this-&gt;width = width;
      this-&gt;calc(); }
  
  // setLength assigns its argument to the private member length.
  void Rectangle::setLength(double length)
  {   this-&gt;length = length;
      this-&gt;calc(); }
  
  // getLength returns the value in the private member length.
  double Rectangle::getLength()
  {   return length; }
  
  // getWidth returns the value in the private member width.
  double Rectangle::getWidth()
  {   return width; }
  
  // getPerimeter returns parameter of box.
  double Rectangle::getPerimeter()
  {   return  this-&gt;perimeter; }
  
  // getArea returns area of box.
  double Rectangle::getArea()
  {   return this-&gt;area; }
  
  // printObjet prints the data of the rectangle
  void Rectangle::printObjet()
  {   cout &lt;&lt; "  Width = " &lt;&lt; getWidth() &lt;&lt; endl;
      cout &lt;&lt; "  Length = " &lt;&lt; getLength() &lt;&lt; endl;
      cout &lt;&lt; "  Perimeter = " &lt;&lt; getPerimeter() &lt;&lt; endl;
      cout &lt;&lt; "  Area = " &lt;&lt; getArea() &lt;&lt; endl &lt;&lt; endl; }
  
  
  // the main program
  int main()
  {
     double width;     // Local variable for width.
     double length;   // Local variable for length.
  
      // create object using constructor
     Rectangle   box1;
     Rectangle   box2;
     Rectangle   box3;
  
     // Get the 1st rectangle's width and length from the user.
     cout &lt;&lt; "Enter the length of the 1st rectangle: ";
     cin &gt;&gt; length;
     cout &lt;&lt; length &lt;&lt; endl;
     cout &lt;&lt; "Enter the width of the 1st rectangle:  ";
     cin &gt;&gt; width;
     cout &lt;&lt; width &lt;&lt; endl;
  
  
      // Store the width and length of the rectangle in the box1 object.
      box1.setWidth(width);
      box1.setLength(length);
  
           // Display box1 data.
      cout &lt;&lt; "You created a rectangle with the following characteristics:" &lt;&lt; endl &lt;&lt; endl;
      box1.printObjet();
  
  
      // Get the 2nd rectangle's width and length from the user.
      cout &lt;&lt; "Enter the length of the 2nd rectangle: ";
      cin &gt;&gt; length;
      cout &lt;&lt; length &lt;&lt; endl;
      cout &lt;&lt; "Enter the width of the 2nd rectangle:  ";
      cin &gt;&gt; width;
      cout &lt;&lt; width &lt;&lt; endl;
  
          // Store the width and length of the rectangle in the box1 object.
          box2.setWidth(width);
          box2.setLength(length);
  
           // Display box2 data.
           cout &lt;&lt; "You created a rectangle with the following characteristics:" &lt;&lt; endl &lt;&lt; endl;
           box2.printObjet();
  
      // Get the 3rd rectangle's width and length from the user.
      cout &lt;&lt; "Enter the length of the 3rd rectangle: ";
      cin &gt;&gt; length;
      cout &lt;&lt; length &lt;&lt; endl;
      cout &lt;&lt; "Enter the width of the 3rd rectangle:  ";
      cin &gt;&gt; width;
      cout &lt;&lt; width &lt;&lt; endl;
  
          // Store the width and length of the rectangle in the box1 object.
          box3.setWidth(width);
          box3.setLength(length);
  
              // Display box3 data.
              cout &lt;&lt; "You created a rectangle with the following characteristics:" &lt;&lt; endl &lt;&lt; endl;
              box3.printObjet();
  
     return 0;
  }
  
  </code></pre>
  
  <p>The compile errors are now</p>
  
  <pre><code>34:1: error: prototype for 'Rectangle::Rectangle(double, double)' does not match any in class 'Rectangle'
   Rectangle::Rectangle(double width, double length)
  </code></pre>
  
  <pre><code>5:7: error: candidates are: constexpr Rectangle::Rectangle(Rectangle&amp;&amp;)
   class Rectangle
  </code></pre>
  
  <pre><code>5:7: error:                 constexpr Rectangle::Rectangle(const Rectangle&amp;)
  </code></pre>
  
  <pre><code>27:1: error:                 Rectangle::Rectangle()
  </code></pre>