Untitled
raw download clone
TEXT
views 19
,
size 586 b
float getDistance(Diem d1, Diem d2) {
        return sqrt(pow(d1.x - d2.x, 2) + pow(d1.y - d2.y, 2));
    }

class DaGiac
{
    int n;
    Diem *d;
    public:
    DaGiac(vector<Diem> dg) {
        n = dg.size();
        d = new Diem[n + 1];
        for(int i = 0; i < n; i++) {
            d[i] = dg[i];
        }
    }
    float tinhChuVi() {
        float perimeter = 0;
        for (int i = 0; i < n - 1; i++) {
            perimeter += getDistance(d[i], d[i+1]);
        }
        perimeter += getDistance(d[0], d[n - 1]);
        return perimeter;
    }
};
close fullscreen
Login or Register to edit or fork this paste. It's free.