fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. class Trig
  6. {
  7. public:
  8. float s(float x,float y,float z);
  9. Trig(float x,float y,float z);
  10. friend float add(Trig &s1,Trig &s2);
  11. private:
  12. float a,b,c;
  13. };
  14. float Trig::s(float x,float y,float z){
  15. float l;
  16. l=0.5*(x+y+z);
  17. return sqrt(l*(l-x)*(l-y)*(l-z));
  18. }
  19. Trig::Trig(float x,float y,float z){
  20. a=x;
  21. b=y;
  22. c=z;
  23. }
  24. float add(Trig &t1,Trig &t2)
  25. {
  26. float x1=t1.s(x,y,z);
  27. float x2=t2.s(x,y,z);
  28. return x1+x2;
  29. }
  30. int main()
  31. {
  32. float x1,y1,z1;
  33. float x2,y2,z2;
  34. cout<<"输入第一个三角形的三边长"<<endl;
  35. cin>>x1>>y1>>z1;
  36. cout<<"输入第二个三角形的三边长"<<endl;
  37. cin>>x2>>y2>>z2;
  38. Trig triangle1(x1,y1,z1);
  39. Trig triangle2(x2,y2,z2);
  40. cout<<triangle1.s(x1,y1,z1)<<" "<<triangle2.s(x2,y2,z2)<<endl;
  41. return 0;
  42. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
1 1 1
2 2 2
compilation info
prog.cpp: In function 'float add(Trig&, Trig&)':
prog.cpp:26:17: error: 'x' was not declared in this scope
   float x1=t1.s(x,y,z);
                 ^
prog.cpp:26:19: error: 'y' was not declared in this scope
   float x1=t1.s(x,y,z);
                   ^
prog.cpp:26:21: error: 'z' was not declared in this scope
   float x1=t1.s(x,y,z);
                     ^
stdout
Standard output is empty