Monday 12 May 2014

virtual base class

#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
class base
{
    private:
    string name;
    int reg_number;
    public:
        void get()
        {
            cout<<"enter your name"<<endl;
            cin>>name;
            cout<<"enter your registration number"<<endl;
            cin>>reg_number;
        }
        void display()
        {
            cout<<"the name of the person is"<<name<<endl;
            cout<<"the registration number of the person is"<<reg_number<<endl;
        }       
};
class derived1 :  public base
{
    private:
    int number1;
    public:
        void get_1()
        {
            cout<<"enter the value of number1"<<endl;
            cin>>number1;
        }
        void show()
        {
            cout<<"the value of the number1 is"<<number1;
        }
};
class derived2 :  public base
{
    private:
    int number2;
    public:
        void get_2()
        {
            cout<<"enter the value of number2"<<endl;
            cin>>number2;
        }
        void display_2()
        {
            cout<<"the value of the number2 is"<<number2<<endl;
        }   
};
class subordinate : public derived1,public derived2
{
    private:
        int number3;
        public:
            void get_3()
            {
                cout<<"enter the value of number3"<<endl;
                cin>>number3;
            }
            void display_3()
            {
                cout<<"the value of number3 is"<<number3<<endl;
            }
};
int main()
{
    subordinate object;
    object.get();
    object.display();
    getch();
    return 0;
}

No comments:

Post a Comment