Describe
Implements a C + + Triangle class that contains 3 points (CPoint type) and completes the area.
The code in the main function is given, please fill it out, and do not include the code that you have given when committing.
int main () {CPoint P1, p2, P3;while (cin>>p1>>p2>>p3) {Ctriangle T (P1, p2, p3); cout<<setiosflags (ios::fixed) <<setprecision (3) <<t.area () <<endl;//call the area function output}return 0;}
Input
The input data has multiple groups, each group contains x1, y1, x2, y2, x3, y3 six integers, representing three points (x1, y1), (x2, y2), (x3, Y3), three points not collinear.
Output
Each group outputs a value, that is, the Triangle area, which retains 3 decimal places.
Sample input
0 0 0 1 1 0
Sample output
0.500
Exercises
Helen formula:The a,b,c in the formula are triangular three-side length, p is half-perimeter, and S is the area of the triangle.
#include <iomanip>#include<iostream>#include<cmath>using namespacestd;classcpoint{ Public: intx, y; CPoint (intx=0,inty=0): X (x), Y (y) {} friend IStream&operator>> (IStream & is,cpoint&p) { is>>p.x>>p.y; return is; }};classctriangle{ Public: CPoint p1,p2,p3; Ctriangle (CPoint p1,cpoint p2,cpoint p3):p 1 (p1), p2 (p2), p3 (p3) {}DoubleArea () {DoubleA=sqrt ((p1.x-p2.x) * (p1.x-p2.x) + (P1.Y-P2.Y) * (p1.y-p2.y)); DoubleB=sqrt ((p1.x-p3.x) * (p1.x-p3.x) + (P1.Y-P3.Y) * (p1.y-p3.y)); DoubleC=sqrt ((p3.x-p2.x) * (p3.x-p2.x) + (P3.Y-P2.Y) * (p3.y-p2.y)); Doublep= (A+B+C) *0.5; DoubleS=sqrt (p* (p-a) * (p-b) * (P-c)); returns; }};intMain () {CPoint P1, p2, p3; while(cin>>p1>>p2>>p3) {Ctriangle T (P1, p2, p3); cout<<setiosflags (iOS::fixed) <<setprecision (3) <<t.area () <<endl;//Call the area function output } return 0;}
"TOJ 5255" C + + Experiment: Triangular area (Helen Formula)