Thursday, October 20, 2011

Single inheritance program using C++


#include<iostream>
using namespace std;
class base
{
public:
int m;
void get_m()
{
cout<<"\n\n\t\tEnter the value of m :";
cin>>m;
}
void disp()
{
cout<<"\n\n\t\tm :"<<m;
}
};
class derived:public base
{
public:
int n,sum;
void get()
{
cout<<"\n\n\t\tEnter the value of n:";
cin>>n;
}

void disp1()
{
cout<<"\n\n\t\tn :"<<n;
}
void calc()
{
cout<<m<<"\n"<<n;
sum=0;
sum=m+n;
cout<<"\n\n\t\tThe sum is :"<<sum;
cout<<"\n";
}
};
int main()
{
derived d;
d.get_m();
d.disp();
d.get();
d.disp1();
d.calc();
return(0);
}

0 comments:

Post a Comment