Program to demonstrate Single Level Inheritance :-
#include<iostream.h>
#include<iostream.h>
#include<conio.h>
class base
{
int a,b;
public:
void base_get()
{
cout<<"\nEnter Value of A: ";
cin>>a;
cout<<"\nEnter Value of B: ";
cin>>b;
}
void base_show()
{
cout<<"\nBASE CLASS DATA ";
cout<<"\nA = "<<a;
cout<<"\nB = "<<b;
}
};
class derived:public base
{
int p,q;
public:
void derived_get()
{
cout<<"\nEnter Value of P: ";
cin>>p;
cout<<"\nEnter Value of Q: ";
cin>>q;
}
void derived_show()
{
cout<<"\nDERIVED CLASS DATA ";
cout<<"\nP= :"<<p;
cout<<"\nQ= :"<<q;
}
};
void main()
{
derived d;
d.base_get();
d.derived_get();
d.base_show();
d.derived_show();
getch();
}
No comments:
Post a Comment