#include<iostream.h>
#include<conio.h>
class base
{
private: int x;
float y;
public:
virtual void getdata( );
virtual void display( );
};
class devb: public base
{
private: int roll;
char name[20];
public: virtual void getdata( );
virtual void display( );
};
class devc : public base
{
private: float height;
float weight;
public : virtual void getdata( );
virtual void display( );
}:
void base :: getdata( )
{
cout<<” Enter any Integer”;
cin>>x;
cout<<”Enter a real no”;
cin>>y;
}
void base ::display( )
{
cout<<”The no X=”<<x<<”Y=”<<y<<endl;
}
void devb :: display( )
{
cout<<”Roll of the Student is:”<<roll<<endl;
cout<<” Name of the Student is: “<<name<<endl;
}
void devb :: getdata( )
{
cout<<”Enter the Roll of the Student:”;
cin>>roll;
cout<<”Enter Name of Student :”;
cin>>name;
}
void devc :: getdata( )
{
cout<<”Enter height and weight”;
cin>>height>>weight;
}
void devc :: display( )
{
cout<<”Height :”<<height<<endl;
cout<<”Weight :”<<weight<<endl;
}
void main( )
{
base *ptr[3];
devb objb;
devc objc;
clrscr( );
ptr[0] = &objb;
ptr[1] = &objc;
ptr[0] ->getdata( );
ptr[1] -> getdata( );
ptr[1] -> display( );
ptr[1] -> display( );
getch ( );
}
OUTPUT
Enter the Roll of the Student: 101
Enter Name of Student : Vineeth
height and weight 170 72
Roll of the Student is:101
Name of the Student is:Vineeth
Height :170
Weight :72
Not Satisfied ? Just search & get the result
Related posts:
