程序运行过了,没有问题,记得给分
#include
#include
class Equation{
float a,b,c;
public:
float x[2];
Equation(float a1=0.0,float b1=0.0,float c1=0.0)
{
a=a1;
b=b1;
c=c1;
}
~Equation(){}
long CalResult();
};
long Equation::CalResult()
{
long temp;
if ((b*b-4*a*c)==0)
{
temp=1;
x[0]=(float)(-(b/2*a));
return temp;
}
if ((b*b-4*a*c)>0)
{
temp=2;
x[0]=(-b+sqrt(b*b-4*a*c))/(2*a);
x[1]=(-b-sqrt(b*b-4*a*c))/(2*a);
return temp;
}
else
{
temp=0;
}
return temp;
}
int main()
{
float a,b,c;
char ch;
do{
cout<<"请输入一元二次方程系数"<
Equation *obj=new Equation(a,b,c);
cout<<"方程有"<
{
cout<<"X="<
if (obj->CalResult()==2)
{
cout<<"X1="<
delete obj;
cout<<"是否继续计算?(1)"<
}while(ch=='1');
return 0;
}