<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\begin{fileverb}
/*----------------------------------------------------------------------*/
/*  FILE:  shapes_v2.cpp (Eighth C++ Lab Exercise 2)                    */
/*  WGET:  wget http://oceanai.mit.edu/cpplabs/shapes_v2.cpp            */
/*  RUN:   shapes_v2                                                    */
/*----------------------------------------------------------------------*/

#include &lt;iostream&gt;      // For use of the cout function
#include "TriangleV2.h"
#include "SquareV2.h"

using namespace std;

int main()
{
  TriangleV2 triangle;
  Vertex t_vertex1(0,0);
  Vertex t_vertex2(10,0);
  Vertex t_vertex3(5,5);
  triangle.addVertex(t_vertex1);
  triangle.addVertex(t_vertex2);
  triangle.addVertex(t_vertex3);

  SquareV2 square;
  Vertex s_vertex1(0,0);
  Vertex s_vertex2(10,0);
  Vertex s_vertex3(10,10);
  Vertex s_vertex4(0,10);
  square.addVertex(s_vertex1);
  square.addVertex(s_vertex2);
  square.addVertex(s_vertex3);
  square.addVertex(s_vertex4);

  cout &lt;&lt; "Triangle:   " &lt;&lt; triangle.getSpec() &lt;&lt; endl;
  cout &lt;&lt; " Perimeter: " &lt;&lt; triangle.getPerimeter() &lt;&lt; endl;    // Added line
  cout &lt;&lt; "Square:     " &lt;&lt; square.getSpec() &lt;&lt; endl;
  cout &lt;&lt; " Perimeter: " &lt;&lt; square.getPerimeter() &lt;&lt; endl;      // Added line

  return(0);
\end{fileverb}
\vspace{0.1in}

\begin{fileverb}
/*----------------------------------------------------------------------*/
/*  FILE:  SegListV2.h                                                  */
/*  WGET:  wget http://oceanai.mit.edu/cpplabs/SegListV2.h              */
/*----------------------------------------------------------------------*/

#ifndef SEGLIST_V2_HEADER
#define SEGLIST_V2_HEADER

#include &lt;string&gt;
#include &lt;vector&gt;
#include "Vertex.h"

class SegListV2 {
 public:
  SegListV2() {};
  ~SegListV2() {};

  void addVertex(Vertex vertex) {m_vertices.push_back(vertex);};

  std::string getSpec() const;

  double getPerimeter() const;

 protected:
  std::vector&lt;Vertex&gt; m_vertices;
};
#endif
\end{fileverb}

\begin{fileverb}
/*----------------------------------------------------------------------*/
/*  FILE:  SegListV2.cpp                                                */
/*  WGET:  wget http://oceanai.mit.edu/cpplabs/SegListV2.cpp            */
/*----------------------------------------------------------------------*/

#include &lt;cmath&gt;           // For including the hypot function
#include "SegListV2.h"

using namespace std;

//-----------------------------------------------------------------------
// Procedure: getSpec

string SegListV2::getSpec() const
{
  string spec;
  for(unsigned int i=0; i&lt;m_vertices.size(); i++) {
    if(i != 0)
      spec += ",";
    spec += m_vertices[i].getSpec();
  }

  return(spec);
}


//-----------------------------------------------------------------------
// Procedure: getPerimeter

double SegListV2::getPerimeter() const
{
  double total = 0;
  for(unsigned int i=0; i&lt;m_vertices.size(); i++) {
    unsigned int next_ix = i+1;
    if((i+1) == m_vertices.size())
      next_ix = 0;
    
    double xdelta = m_vertices[i].getX() - m_vertices[next_ix].getX();
    double ydelta = m_vertices[i].getY() - m_vertices[next_ix].getY();
    double dist = hypot(xdelta, ydelta);
    total += dist;
  }

  return(total);
}
\end{fileverb}

\begin{fileverb}
/*----------------------------------------------------------------------*/
/*  FILE:  TriangleV2.h                                                 */
/*  WGET:  wget http://oceanai.mit.edu/cpplabs/TriangleV2.h             */
/*----------------------------------------------------------------------*/

#ifndef TRIANGLE_V2_HEADER
#define TRIANGLE_V2_HEADER

#include "SegListV2.h"

class TriangleV2 : public SegListV2 {
 public:
  TriangleV2() {};
  ~TriangleV2() {};

  std::string getSpec() const;
};

#endif
\end{fileverb}

\begin{fileverb}
/*----------------------------------------------------------------------*/
/*  FILE:  TriangleV2.cpp                                               */
/*  WGET:  wget http://oceanai.mit.edu/cpplabs/Triangle.cpp             */
/*----------------------------------------------------------------------*/

#include "TriangleV2.h"

using namespace std;

//-----------------------------------------------------------------------
// Procedure: getSpec()

string TriangleV2::getSpec() const
{
  string spec = "type=triangle,";
  spec += SegListV2::getSpec();
  return(spec);
}
\end{fileverb}


\begin{fileverb}
/*----------------------------------------------------------------------*/
/*  FILE:  SquareV2.h                                                   */
/*  WGET:  wget http://oceanai.mit.edu/cpplabs/SquareV2.h               */
/*----------------------------------------------------------------------*/

#ifndef SQUARE_V2_HEADER
#define SQUARE_V2_HEADER

#include "SegListV2.h"

class SquareV2 : public SegListV2 {
 public:
  SquareV2() {};
  ~SquareV2() {};

  std::string getSpec() const;
};
#endif
\end{fileverb}

\begin{fileverb}
/*----------------------------------------------------------------------*/
/*  FILE:  SquareV2.cpp                                                 */
/*  WGET:  wget http://oceanai.mit.edu/cpplabs/TriangleV2.cpp           */
/*----------------------------------------------------------------------*/

#include "SquareV2.h"

using namespace std;

//-----------------------------------------------------------------------
// Procedure: getSpec()

string SquareV2::getSpec() const
{
  string spec = "type=square,";
  spec += SegListV2::getSpec();
  return(spec);
}
\end{fileverb}


</pre></body></html>