title: C++ how to find area of square or rectangle with vector of coordinates
body: <p>How do I find the area of square or rectangle assuming user has entered some accurate points to form a square or rectangle. </p>
  
  <p>I need to calculate the area inside the square class and rectangle class respectively. </p>
  
  <p>I have 2 vector of coordinates, coordX and coordY. </p>
  
  <p>My idea is when either or x or y has same value it will be a line and I can find the distance x2 but I'm not sure how to implement it in code. </p>
  
  <pre><code>double Square::computeArea() {
  
      double area;
  
      for (int x = 0; x &lt; coordX.size; x++) {
          for (int y = 0; y &lt; coordY.size; y++) {
              if (coordX[x] == coordY[y])
              {
                  //....
              }   
          }
      }       
      return area;
  }
  </code></pre>
  
  <p>This is how i populate my vector with user input </p>
  
  <pre><code>    Square Square;
  
      for ( int i = 1; i &lt;= 4; i++) {
  
          cout &lt;&lt; "Please enter x-coordinate of pt " &lt;&lt; i &lt;&lt; ": ";    
  
          cin &gt;&gt; x;
  
          Square.setXCoordinate(x);
  
          cout &lt;&lt; "Please enter y-coordinate of pt " &lt;&lt; i &lt;&lt; ": ";    
  
          cin &gt;&gt; y;       
  
          Square.setYCoordinate(y);
  
      }
  </code></pre>
  
  <p>this is my mutator function in my class. Square inherit from ShapeTwoD</p>
  
  <pre><code>void ShapeTwoD::setXCoordinate(int x) {
      coordX.push_back(x);
  }
  
  void ShapeTwoD::setYCoordinate(int y) {
      coordY.push_back(y);
  } 
  </code></pre>