contain

#include<iostream>
#include<cmath>
using namespace std;
class Point
{
    double x,y;
public:
    Point(double x = 0,double y = 0)
    {
        this -> x = x;
        this -> y =y;
    }
    double getx()
    {
        return x;
    }
    double gety()
    {
        return y;
    }
};
class Line
{
    Point p1,p2;
public:
    Line(const Point &a,const Point &b): p1(a),p2(b) {}
    double getDistance()
    {
        double detax,detay;
        detax = p1.getx() - p2.getx();
        detay = p1.gety() - p2.gety();
        return sqrt(detax * detax + detay * detay);
    }
};
class Triangle
{
    Line z1,z2,z3;
public:
    Triangle(const Line &a,const Line &b,const Line &c):z1(a),z2(b),z3(c) {}
    double Area()
    {
        double p,q;
        p=((z1.getDistance()+z2.getDistance()+z3.getDistance())/2);
        q=sqrt(p*((p-z1.getDistance())*(p-z2.getDistance())*(p-z3.getDistance())));
        return q;
    }
};
int main()
{
    float p1,p2,p3,p4,p5,p6;
    cin>>p1>>p2>>p3>>p4>>p5>>p6;
    Point a(p1,p2),b(p3,p4),c(p5,p6);
    Line d(a,b),e(b,c),f(c,a);
    Triangle z(d,e,f);
    double distance,area;
    distance=d.getDistance()+e.getDistance()+f.getDistance();
    area=z.Area();
    cout<<distance<<' '<<area<<endl;
    return 0;
}

Guess you like

Origin www.cnblogs.com/handsometaoa/p/11008276.html