Monday, 12 March 2012

Program of Type Conversion Between Base to Derive Class


#include <iostream.h>
#include<conio.h>
class Base
{
private:
    double b;
public:

    Base(double x)
    {
     b=x;
    }
    {
cout<<"\n Base Class Value Is"<<b;
    }
    double getValue()
    {
return b;
    }
};
class derive
{
private:
    double d;
public:
    derive(Base y)
    {
     d=y.getValue() * 1.6987;
    }
    void display()
    {
      cout << "\n derive Value Is"<<d;
    }
};
main()
{
clrscr();
    Base m1(100);        // Source Class
    derive k1 = m1;         // Destination Class
    m1.display();
    k1.display();
    cout << endl;
   getch();
}

No comments:

Post a Comment