by Dinesh Thakur Category: Classes in C++

 

#include<math.h>

#include<iostream.h>
#include<conio.h>
#include<process.h>
class quadratic
{
     private:
     double a,b,c;
     public:
                  void read();
                  void funcroots();
};
              void quadratic::read()
        {
              cout<<"Enter coffiecients of Quadratic Eq. a,b,c";
              cin>>a>>b>>c;
        }
             void quadratic::funcroots()
       {
            if(a==0)
             {
                   cout<<"\nEquations is not quadratic";
                   exit(0);
            }
         else
         {
                  double disc;
                  disc=b*b-4 *a*c;
                  if(disc<0)
                     cout<<"\nRoots are Imaginary";
                  else if(disc==0)
                         {
                                double x=-b/(2*a);
                                cout<<"\nRoots are Equal,x= u"<<x;
                         }
                  else
                        {
                                double m,n,t;
                                t=sqrt(disc);
                                m=( -b+t)/(2*a);
                                n=(-b-t)/(2*a);
                                cout<<"\nRoots are Real and Unequal"<<endl;
                                cout<<"m="<<m<<endl;
                                cout<<"n="<<n;
                        }
           }
    }
             void main()
        {
               clrscr();
               quadratic q1 ;
               q1.read();
               q1.funcroots();
               getch();
       }

Abstraction, Data Hiding, Encapsulation

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content







Popular Article