qq_34872175 于 2016.05.03 22:29 提问

C++问题求助，求大神解答一下困惑

#include
#include
using namespace std;

class Trig
{
public:
float s(float x,float y,float z);
Trig(float x,float y,float z);
private:
float a,b,c;
};
float Trig::s(float x,float y,float z){
float l;
l=0.5*(x+y+z);
return sqrt(l*(l-x)*(l-y)*(l-z));
}
Trig::Trig(float x,float y,float z){
a=x;
b=y;
c=z;
}
{
float x1=t1.s(x,y,z);
float x2=t2.s(x,y,z);
return x1+x2;
}
int main()
{
float x1,y1,z1;
float x2,y2,z2;
cout<<"输入第一个三角形的三边长"< cin>>x1>>y1>>z1;
cout<<"输入第二个三角形的三边长"< cin>>x2>>y2>>z2;
Trig triangle1(x1,y1,z1);
Trig triangle2(x2,y2,z2);
cout<<triangle1.s(x1,y1,z1)<<" "<<triangle2.s(x2,y2,z2)<<endl;
return 0;
}

4个回答

a854073071   2016.05.05 21:47

float Triangle::s()
{
float l;
l = 0.5 * (a + b + c);
return sqrt(l * (l - a) * (l - b) * (l - c));
}

{
float x1 = t1.s();
float x2 = t2.s();

``````return (x1 + x2);
``````

}

caozhy      2016.05.04 06:10

http://ideone.com/3VNf8q

float Trig::s(float x,float y,float z)

qq_34872175 那我怎么用友元函数计算俩三角形面积和啊？

ZGZ1002   2016.05.04 16:03