Sunday, January 1, 2012

Find a given root is same or different in a given quadratic equation in 'C++'

Example



#include<iostream.h>
#include<conio.h>
#include<math.h>
class quadratic
{
int a,b,c;
float delta,alpha,beta;
public:
void getdata()
{
cout<<"Enter the value of quadratic equation:::";
cin>>a>>b>>c;
}
void putdata();
};
void quadratic::putdata()
{
delta=(b*b)-4*a*c;
if(delta>0)
{
alpha=(-b+sqrt(delta))/2*a;
beta=(-b-sqrt(delta))/2*a;
cout<<"Root is diferent"<<endl;
cout<<"value of two root is::"<<alpha<<endl<<beta;
}
else if(delta==0)
{
alpha=(-b+sqrt(delta))/2*a;
beta=(-b-sqrt(delta))/2*a;
cout<<"Root is same"<<endl;
cout<<"value of two root is::"<<alpha<<endl<<beta;
}
else
{
cout<<"No root is there";


}
}
int main()
{
quadratic q1;
clrscr();
q1.getdata();
q1.putdata();
getch();
return 0;
}
/*=============================================================
OUTPUT
Enter the value of quadratic equation:::5
4
3
No root is there
*/

No comments:

Post a Comment