//Multilevel Inheritance
#include<iostream.h>
#include<conio.h>
class A1 //Base Class
{
protected:
char name[15];
int age;
};
class A2:public A1 //Derivation First Level
{
protected:
float height;
float weight;
};
class A3:public A2 //Derivation Second Level
{
protected:
char sex;
public:
void get()
{
cout<<"Name=";cin>>name;
cout<<"Age=";cin>>age;
cout<<"Sex=";cin>>sex;
cout<<"Height=";cin>>height;
cout<<"Weight=";cin>>weight;
}
void show()
{
cout<<"\nName="<<name<<endl;
cout<<"Age="<<age<<endl;
cout<<"Sex="<<sex<<endl;
cout<<"Height="<<height<<endl;
cout<<"Weight="<<weight<<endl;
}
};
void main()
{
//clrscr();
A3 x;
x.get();
x.show();
getch();
}
#include<iostream.h>
#include<conio.h>
class A1 //Base Class
{
protected:
char name[15];
int age;
};
class A2:public A1 //Derivation First Level
{
protected:
float height;
float weight;
};
class A3:public A2 //Derivation Second Level
{
protected:
char sex;
public:
void get()
{
cout<<"Name=";cin>>name;
cout<<"Age=";cin>>age;
cout<<"Sex=";cin>>sex;
cout<<"Height=";cin>>height;
cout<<"Weight=";cin>>weight;
}
void show()
{
cout<<"\nName="<<name<<endl;
cout<<"Age="<<age<<endl;
cout<<"Sex="<<sex<<endl;
cout<<"Height="<<height<<endl;
cout<<"Weight="<<weight<<endl;
}
};
void main()
{
//clrscr();
A3 x;
x.get();
x.show();
getch();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.