SOURCE CODE:
#include<iostream.h>
#include<conio.h>
class base
{
int a;
public:
int b;
void get_ab();
int get_a();
void show();
};
void base::get_ab()
{
cout<<"\n Enter the value for a and b:\n";
cin>>a>>b;
}
int base::get_a()
{
return a;
}
void base::show()
{
cout<<"\n\nThe entered values are:\t"<<a<<"\t "<<b;
}
class derived:public base
{
int add;
public:
void cal();
void display();
};
void derived::cal()
{
get_ab();
add=get_a()+b;
}
void derived::display()
{
show();
cout<<"\n\n Addition="<<add;
}
void main()
{
derived D;
D.cal();
D.display();
getch();
}
OUTPUT:
Enter the value for a and b:
20
30
The entered values are: 20 30
Addition=50
EmoticonEmoticon