马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <iostream>
#include <cstring>
#include<math.h>
using std::cout;
using std::endl;
class Point{
private:
double x, y;
public:
Point(double xx, double yy)
{
x=xx;
y=yy;
}
double getX()
{
return x;
}
double getY()
{
return y;
}
};
class Triangle{
private:
Point a, b, c;
public:
Triangle():a(5.8,3.3),b(3.3,4.2),c(6.6,7.8)
{}
Triangle(double x1,double y1,double x2,double y2,double x3,double y3):a(x1,y1),b(x2,y2),c(x3,y3)
{}
Triangle(Point p1,Point p2,Point p3){}//这边要怎么初始化?
double getSideA()
{
double sidea;
sidea=sqrt((b.getX()-c.getX())*(b.getX()-c.getX())+(b.getY()-c.getY())*(b.getY()-c.getY()));
return sidea;
}
double getSideB()
{
double sideb;
sideb=sqrt((a.getX()-c.getX())*(a.getX()-c.getX())+(a.getY()-c.getY())*(a.getY()-c.getY()));
return sideb;
}
double getSideC()
{
double sidec;
sidec=sqrt((b.getX()-a.getX())*(b.getX()-a.getX())+(b.getY()-a.getY())*(b.getY()-a.getY()));
return sidec;
}
double getArea()
{
double s,area,x,y,z;
x=getSideA();
y=getSideB();
z=getSideC();
s=getSideA()+getSideB()+getSideC();
area=sqrt(s*(s-x)*(s-y)*(s-z));
return area;
}
double getPeri()
{
double s;
s=getSideA()+getSideB()+getSideC();
return s;
}
};
int main()
{
Triangle T1(1.7,8.8,4.3,2.2,6.6,7.7),T2;
cout<<"T1的面积为:"<<T1.getArea()<<endl;
cout<<"T1的周长为:"<<T1.getPeri()<<endl;
cout<<"T2的面积为:"<<T2.getArea()<<endl;
cout<<"T2的周长为:"<<T2.getPeri()<<endl;
return 0;
}
|