编写一类Cpoint表示一个点的信息。在此基础上编写一个表示三角形的类tria,顶点为其对象成员。编写完整的程序输出三角形的面积.
出现这样的问题:'-' : illegal, right operand has type 'int (__thiscall Cpoint::*)(void)'
下面是我编写的程序:
#include
#include
class Cpoint
{public:
Cpoint(int xx=0,int yy=0)
{X=xx;Y=yy;}
int GetX(){return X;}
int GetY(){return Y;}
private:
int X,Y;
};
class tria
{
public:
Cpoint A,B,C;
double l1,l2,l3,t;
double area;
double Getl1()
{X=(A.GetX)-(B.GetX);Y=(A.GetY)-(B.GetY);
return sqrt((double)(X*X+Y*Y));
}
double Getl2()
{X=A.GetX-C.GetX;Y=A.GetY-C.GetY;
return sqrt((double)(X*X+Y*Y));
}
double Getl3()
{X=C.GetX-B.GetX;Y=C.GetY-B.GetY;
return sqrt((double)(X*X+Y*Y));
}
double Gett()
{double t;
t=(l1+l2+l3)/2;
return t;
}
double Getarea()
{ area=sqrt((double)(t*(t-l1)*(t-l2)*(t-l3)));
return area;
cout<<"三角形的面积:"<}
};
void main()
{Cpoint A(0,0),B(0,3),C(4,0);
tria K;
K.Getl1();
K.Getl2();
K.Getl3();
K.Gett();
K.Getarea();
}
--------------------next---------------------
阅读(1119) | 评论(0) | 转发(0) |