קוד:
#include <stdio.h>
#include <iostreams.h>
#include <math.h>
//finish compiling erorrs, restore private
class point {
public:
double x, y;
public:
point(double x1, double y1): x(x1), y(y1) {}
int make_point(double x1, double y1){
x=x1;
y=y1;
return 0;
}
int operator==(point a){
if (x==a.x && y==a.y) return 1;
else return 0;
}
}
class line {
public:
double length;
point p1, p2;
public:
int make_line (point a, point b){
p1.make_point(a.x, a.y);
p2.make_point(b.x, b.y);
length=sqrt( (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y));
return 0;
}
}
class tryangle {
public:
point p1, p2, p3;
line l1, l2, l3;
double area, perimeter;
public:
tryangle(point a, point b, point c) {
p1.make_point(a.x, a.y);
p2.make_point(b.x, b.y);
p3.make_point(c.x, c.y);
l1.make_line(p1, p2);
l2.make_line(p1, p3);
l3.make_line(p2, p3);
perimeter=l1.length+l2.length+l3.length;
area=sqrt(perimeter/2*(perimeter/2-l1.length)*(perimeter/2-l2.length)*(perimeter/2-l3.length));
}
int check(void){
if(p1==p2 || p1==p3 || p2==p3){
printf("Illegal triangle. Some points coincide. Bye...\n");
return 1;
}
if(fabs( (p3.y-p1.y) * (p2.x-p1.x) - (p2.x-p1.x) * (p3.x-p1.x) ) < 0.001 ) { {
printf("Illegal triangle. Three points on one line. Bye...\n");
return 1;
}
return 0;
}
}
int main(void){
double x1, x2, x3,
y1, y2, y3;
/*if(scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3)!=6){
printf("incorrect data!\n");
return 1;
}*/
cin>> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
point p1(x1, y1), p2(x2, y2), p3(x3, y3);
tryangle t1(p1, p2, p3);
if(t1.check()){
return 1;
}
printf("The edge length: a=%.2lf, b=%.2lf, c=%.2lf\n", t1.l1.length, t1.l2.length, t1.l3.length);
printf("The perimeter of the triangle is %.2lf\n", t1.perimeter);
printf("The area of the triangle is %.2lf\n", t1.area);
return 0;
}