Pages

Tuesday, October 11, 2011

3.Inheritance

WAP USING INHERITANCE TO APPLY SHRIDACHARYA'S FORMULAE i.e,Calculate real roots if (d>=0)



#include<iostream.h>
#include<conio.h>
#include<math.h>
class coeff
{
protected:
float a,b,c;
};
class read_coeff:virtual public coeff
{
public:
read_coeff()
{
cout<<"\n\nEnter the value of a,b & c::";
cin>>a>>b>>c;
}
};
class calc_root:virtual public coeff
{
protected:
float d,x1,x2;
public:
calc_root()
{
d=sqrt(b*b-4*a*c);
if(d>=0)
{
x1=(-b+d)/(2*a);
x2=(-b-d)/(2*a);
}
}
};
class disp:public read_coeff,public calc_root
{
public:
disp()
{
cout<<"\nx1::"<<x1;
cout<<"\nx2::"<<x2;
}
};
void main()
{
clrscr();
disp d;
getch();
}

No comments: