描述
实现C++三角形类,其中包含3个点(CPoint类型),并完成求面积。
主函数里的代码已经给出,请补充完整,提交时请勿包含已经给出的代码。
int main()
{
CPoint p1, p2, p3;
while(cin>>p1>>p2>>p3)
{
CTriangle t(p1, p2, p3);
cout<
#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;
}
};