Sunday, January 1, 2012

Hirarchical inheritence in 'C++'

Example



#include<iostream.h>
#include<conio.h>
class emp
{
protected:
char nm[10],rno[10];
int hra,da,bs;
public:
void getdata()
{
cout<<"ENTER EMPNO, NAME  OF EMPLOYEE::";
cin>>rno>>nm;
}
void getallowance()
{
cout<<"\nENTER HRA,DA AND BS OF EMPLOYEE:";
cin>>hra>>da>>bs;
}
    };
class res1:public emp
{
public:
void putdata()
{
cout<<"\n\nEmpno:"<<rno<<endl<<"Empname:"<<nm;
}
   };
class res2:public emp
{
float incom;
public:
void result()
{
incom=(hra+da+bs)*0.12;
cout<<"\nHRA:"<<hra<<endl<<"DA:"<<da<<endl<<"BS:"<<bs;
cout<<"\nINCOME TAX:"<<incom;
}
};
int main()
{
clrscr();
res1 r;
res2 r1;
r.getdata();
r1.getallowance();
r.putdata();
r1.result();
getch();
return 0;
}
/*===============================================================
output
ENTER EMPNO, NAME  OF EMPLOYEE::E101
ANISH


ENTER HRA,DA AND BS OF EMPLOYEE:2222
333
4444




Empno:E101
Empname:ANISH
HRA:2222
DA:333
BS:4444
INCOME TAX:839.880005
*/

No comments:

Post a Comment