#include
#include
Using namespace STD.
The class Area
{
Public:
Void (In);
Void Calucate ();
Void Out ();
Private:
Int N;
Float sum;
Float x1, x2, x3, y1, y2, y3.
};
Void Area: : (In)
{
sum=0;
Cout & lt; <"Input polygon vertices:";
Cin & gt;> N;
Cout & lt; <"Input coordinates according to the polygon vertex clockwise or counterclockwise input!"
{
Cout & lt; <"Please input the first vertex coordinates:";
Cin & gt;> The x1 & gt;> Y1.
Cout & lt; <"Please enter the second vertex coordinates:";
Cin & gt;> X2 & gt;> Y2.
Cout & lt; <"Please enter the third vertex coordinates:";
Cin & gt;> The x3 & gt;> Y3.
Calucate ();
} the else
{
Cout & lt; <"Please input the first vertex coordinates:";
Cin & gt;> The x1 & gt;> Y1.
Cout & lt; <"Please enter the second vertex coordinates:";
Cin & gt;> X2 & gt;> Y2.
Cout & lt; <"Please enter the third vertex coordinates:";
Cin & gt;> The x3 & gt;> Y3.
Calucate ();
For (int I=3; I
Cout & lt; <"Please enter the first" & lt; If ((I + 1) % 2==0)
{
Cin & gt;> X2 & gt;> Y2.
Calucate ();
} the else
{
Cin & gt;> The x3 & gt;> Y3.
Calucate ();
}
}
}
}
Void Area: : Calucate ()
{
Float Cir, L1, L2, L3;
L1=SQRT ((x1, x2) * (x1, x2) + (y1, y2) * (y1, y2));
L2=SQRT ((x1 - x3) * (x1 - x3) + (y1, y3) * (y1, y3));
L3=SQRT ((x2, x3) * (x2 x3) + (y2, y3) * (y2, y3));
Cir=(L1 + L2 + l)/2;
The sum +=SQRT (Cir * (Cir - L1) * (Cir - L2) * (Cir - L3));
}
Void Area: : Out ()
{
Cout & lt; <"The polygon area is:" & lt;
Int main ()
{
Area polygon;
Polygon. (In);
Polygon. Out ();
Return 0;
}
A defect but this method is that the input polygon vertex coordinates must be clockwise or counterclockwise input, otherwise will calculation error,
CodePudding user response:
How can I solve random input coordinates rather than clockwise or counterclockwise,CodePudding user response:
The