TZOJ5255: C++实验:三角形面积
作者:互联网
#include<iostream> #include<iomanip> #include<math.h> #include<cmath> using namespace std; class CPoint { public: int x,y; CPoint(int x=0,int y=0):x(x),y(y){} friend istream &operator>>(istream &is,CPoint &p) { is>>p.x>>p.y; return is; } }; class CTriangle { public: CPoint p1,p2,p3; CTriangle(CPoint p1,CPoint p2,CPoint p3):p1(p1),p2(p2),p3(p3){} double Area() { double a=sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); double b=sqrt((p1.x-p3.x)*(p1.x-p3.x)+(p1.y-p3.y)*(p1.y-p3.y)); double c=sqrt((p3.x-p2.x)*(p3.x-p2.x)+(p3.y-p2.y)*(p3.y-p2.y)); double p=(a+b+c)/2.0; double s=sqrt(p*(p-a)*(p-b)*(p-c)); return s; } };
标签:p2,p3,p1,TZOJ5255,double,C++,CPoint,sqrt,三角形 来源: https://www.cnblogs.com/zzjam--1/p/11478695.html