All about programming in GNU/LINUX

illustration of Pure virtual functions

#include<iostream>
using namespace std;
class number
{
    protected:
    int val;
    public:
    void setval(int i)
    {
        val=i;
    }
   virtual void show()=0;

};
class hextype:public number
{
    public:
    void show()
    {
        cout<<“Hextype:”;
        cout<<hex<<val<<“\n”;
    }
};
class dectype:public number
{
    public:
    void show()
    {
        cout<<“Decimal: “;
        cout<<val<<“\n”;

    }
};
class octtype:public number
{
    public:
    void show()
    {
        cout<<“Octal : “;
        cout<<oct<<val<<“\n”;

    }
};
int main()
{
    dectype d;
    hextype h;
    octtype o;
    d.setval(100);
    d.show();
    h.setval(100);
    h.show();
    o.setval(100);
    o.show();
}

Image

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s