C++的给出多边形定点坐标,求周长问题

来源:百度知道 编辑:UC知道 时间:2024/05/29 13:40:47
要求用C++实现一个程序,使用户可以顺次输入N个坐标顶点,求出该坐标组成多边形的周长(不考虑凹凸多边形问题)。
解决我可以再补加分

#include <math.h>
#include <iostream>
using namespace std;

struct POINT
{
float x;
float y;
};

class Polygon
{
public:
Polygon();
~Polygon();

int InitPolygonByArray(POINT* pArray, int nCount);
float CalcPerimeter();

protected:
float CalcDistanceBetweenTwoVertex(POINT ptBegin, POINT ptEnd);

protected:
POINT* m_pVertexArray;
int m_nVertexCount;
};

Polygon::Polygon()
{
m_pVertexArray = NULL;
m_nVertexCount = 0;
}

Polygon::~Polygon()
{
if(m_pVertexArray != NULL)
delete[] m_pVertexArray;
m_nVertexCount = 0;
}

int Polygon::InitPolygonByArray(POINT* pArray, int nCount)
{
if(pArray == NULL || nCount < 3)
return -1;

if(m_pVertexArray != NULL)
delete[] m_pVertexArray;

m_nVertexCount = nCount;
m_pVertexArr