计算三角形的面积和周长, 1.先设计一个POINT类,包括其构造方法设置和修改坐标,求解两点距离
1个回答
展开全部
class point
{
int x;
int y;
public:
point (int x1=0,int y1=0) {x=x1;y=y1;};
virtual ~point() {};
void alt(int x2,int y2)
{
x=x2;y=y2;
}
void copy(point b)
{
x=b.x;y=b.y;
}
int dis(point a)
{
int c=pow(x-a.x)+pow(y-a.y);
int b=sqrt(c);
return b;
}
}
class triangle::public point
{
point a;
point b;
point c;
public:
triangle (point a1,point b1,point c1){a.copy(a1);b.copy(b1);c.copy(c1);}
virtual ~triangle();
int cir()
{
int ab=a.dis(b);
int bc=b.dis(c);
int ca=c.dis(a);
return ab+bc+ca;
}
int squ()
{
int n=a.dis(b)+b.dis(c)+c.dis(a);
int m=a.dis(b)+b.dis(c)-c.dis(a);
int o=a.dis(b)-b.dis(c)+c.dis(a);
int p=-a.dis(b)+b.dis(c)+c.dis(a);
return sqrt(n*m*o*p)/4
}
}
{
int x;
int y;
public:
point (int x1=0,int y1=0) {x=x1;y=y1;};
virtual ~point() {};
void alt(int x2,int y2)
{
x=x2;y=y2;
}
void copy(point b)
{
x=b.x;y=b.y;
}
int dis(point a)
{
int c=pow(x-a.x)+pow(y-a.y);
int b=sqrt(c);
return b;
}
}
class triangle::public point
{
point a;
point b;
point c;
public:
triangle (point a1,point b1,point c1){a.copy(a1);b.copy(b1);c.copy(c1);}
virtual ~triangle();
int cir()
{
int ab=a.dis(b);
int bc=b.dis(c);
int ca=c.dis(a);
return ab+bc+ca;
}
int squ()
{
int n=a.dis(b)+b.dis(c)+c.dis(a);
int m=a.dis(b)+b.dis(c)-c.dis(a);
int o=a.dis(b)-b.dis(c)+c.dis(a);
int p=-a.dis(b)+b.dis(c)+c.dis(a);
return sqrt(n*m*o*p)/4
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询