Регистрация
Войти
Стать экспертом Правила
Информатика

По координатам трёх вершин некооторого треугольника найдите его площадь и периметр

ОТВЕТЫ
#include lt;iostreamgt;
#include lt;math.hgt;

using namespace std;

class Vertice {
public:
    double x, y;
    friend istream amp;operatorgt;gt;(istream amp;is, Vertice amp;v) {
        is gt;gt; v.x gt;gt; v.y ;
    }
    double distance(Vertice amp;w);
};

double Vertice::distance(Vertice amp;w) {
    return sqrt( pow(this-gt;x-w.x,2) + pow(this-gt;y-w.y,2));
}

class Triangle {
public:
    Vertice a, b, c;
    Triangle(Vertice v, Vertice w, Vertice u);
    double Square();
    double Perimetr();
};

Triangle::Triangle(Vertice v, Vertice w, Vertice u) {
    this-gt;a = v, this-gt;b = w, this-gt;c = u;
}

double Triangle::Perimetr() {
    return this-gt;a.distance(this-gt;b) + this-gt;a.distance(this-gt;c) + this-gt;b.distance(this-gt;c);
}

double Triangle::Square() {
    double a = this-gt;a.distance(this-gt;b), b = this-gt;b.distance(this-gt;c), c = this-gt;a.distance(this-gt;c),
        p = (a+b+c)/2;
    return sqrt(p*(p-a)*(p-b)*(p-c));
}

int main() {
    Vertice a, b , c;
    cin gt;gt; a gt;gt; b gt;gt; c;
    Triangle t(a,b,c);
    cout lt;lt; t.Perimetr() lt;lt; endl lt;lt; t.Square() lt;lt; endl;
}

//язык c++, ООП
1
Контакты
Реклама на сайте
Спрошу
О проекте
Новым пользователям
Новым экспертам