
460 Inheritance
{
int e;
public:
void getdata()
{
cout<<“\n Enter values of a,b,c & d & e:”;
cin>>a>>b>>c>>d>>e;
}
void showdata()
{
cout<<“\n a=”<<a <<“ b=”<<b <<“ c = ”<<c <<“ d= ”<<d <<“ e=”<<e;
}
};
int main()
{
clrscr();
E x;
x.getdata(); // Reads data
x.showdata(); // Displays data
return 0;
}
OUTPUT
Enter values of a,b,c & d & e : 1 2 4 8 16
a=1 b = 2 c = 4 d= 8 z= 16
Explanation: In the above program, classes A, B, C, D, and E are declared with a
one-integer member variable each. The class E has a two-member function getdata() and
showdata(), respectively. The getdata() is used to read integers through the keyboard,
and ...