简单的C++题 结果正确 但结果后输出了1.#QNAN,为什么?
程序代码:
#include<iostream> #include<math.h> using namespace std; class Triangle { private: float a,b,c; public: Triangle() { cout<<"输入三角形三边"<<endl; } ~Triangle() { cout<<"over"<<endl; } void getabc(); int judge(); float ZC(); float MJ(); float LX(); }s1; void Triangle ::getabc() { cin>>a; cin>>b; cin>>c; } int Triangle::judge() { if(a+b>c&&a-b<c&&a!=0&&b!=0&&c!=0) return 1; else return 0; } float Triangle::ZC() { return a+b+c; } float Triangle::MJ() { float area,p; p=ZC()/2; area=sqrt((p-a)*(p-b)*(p-c)*p); return area; } float Triangle:: LX() { if(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a) cout<<"直角三角形"<<endl; else if(a*a+b*b<c*c||a*a+c*c<b*b||b*b+c*c<a*a) cout<<"钝角三角形"<<endl; else cout<<"锐角三角形"<<endl; } int main() { s1.getabc(); if(s1.judge()==0) cout<<"不是三角形"<<endl; else{ cout<<s1.ZC()<<endl; cout<<s1.MJ()<<endl; cout<<s1.LX()<<endl; } }