You are on page 1of 2

#include<iostream>

#include<cstdlib>
#include<math.h>
class equation
{
private:
float a;
float b;
float c;
public:
void getinfo(float a,float b, float c);
void display();
void equal(float a,float b);
void imag();
void real(float a,float b,float det);
};
void equation::getinfo(float aa,float bb,float cc)
{
a=aa;
b=bb;
c=cc;
}
void equation::display()
{
std::cout<<std::endl;
std::cout<<"a="<<a<<"\n";
std::cout<<"b="<<b<<"\n";
std::cout<<"c="<<c<<std::endl;
}
void equation::equal(float a,float b)
{
float x;
x=-b/(2*a);
std::cout<<"Roots are equal="<<x<<std::endl;
}
void equation::imag()
{
std::cout<<"Roots are imaginary\n";
}
void equation::real(float a,float b,float det)
{
float x1,x2,temp;
temp=sqrt(det);
x1=(-b+temp)/(2*a);
x2=(-b-temp)/(2*a);
std::cout<<"Roots are real\n";
std::cout<<"x1="<<x1<<std::endl;
std::cout<<"x2="<<x2<<std::endl;
}
int main()
{
equation eq;
float aa,bb,cc;
system("cls");
std::cout<<"Enter three numbers\n";
std::cin>>aa>>bb>>cc;
eq.getinfo(aa,bb,cc);
eq.display();
if(aa==0)
{
float temp;
temp=cc/bb;
std::cout<<"linear roots+"<<temp<<std::endl;
}
else
{
float det;
det=bb*bb-4*aa*cc;
if(det==0)
eq.equal(aa,bb);
else if(det<0)
eq.imag();
else
eq.real(aa,bb,det);
}
std::cin.get();
return 0;
}

You might also like