c++ programs examples

C++ Program to inherit class C from A and B, where A and B has Pure Virtual Functions

c++ programs examples

/* 8. Write a program to inherit class C from A and B, where A and B has

       Pure Virtual Functions. */

 #include<iostream.h>

 #include<conio.h>

 class A

 {

  protected:

   int a,b;

  public:

   A()

   {

    a=b=0;

    }

   virtual void display()=0;

   virtual void input()

   {

    int x,y;

    cout<<“Enter two Value for Class A”<<endl;

    cin>>x>>y;

    a=x;

    b=y;

    }

 };

 class B

 {

  protected:

   int c,d;

  public:

   B()

   {

    c=d=0;

    }

   virtual void display()=0;

   virtual void input()

   {

    int z,w;

    cout<<“Enter two value for Class B”<<endl;

    cin>>z>>w;

    c=z;

    d=w;

    }

 };

 class C: public A, public B

 {

  private:

   int e,f;

  public:

   C()

   {

    e=f=0;

    }

   void input()

   {

   int p,q;

   A::input();

   B::input();

   cout<<“Enter two value for class C”<<endl;

   cin>>p>>q;

   e=p;

   f=q;

   }

   void display()

   {

    cout<<“a=”<<a<<endl<<“b=”<<b<<endl<<“c=”<<c<<endl

            <<“d=”<<d<<endl<<“e=”<<e<<endl<<“f=”<<f<<endl;

    }

 };

 void main()

 {

  clrscr();

  C obj1;

  obj1.input();

  obj1.display();

  getch();

  }

Leave a Reply

Your email address will not be published. Required fields are marked *