PROGRAM – 4
Write
a program to implement the following class hierarchy
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class
Person
{
int age ;
char name [ 20 ];
public :
void getdata ( )
{
cout<<"Enter the
Name & age ";
gets( name ) ;
cin >> age ;
}
void putdata ( )
{
cout <<"\nName :
"; puts( name );
cout<<"Age :"<<age ;
}
};
class
Employee : public Person
{
float salary ;
char designation[ 30 ];
public :
void getdata ( )
{
Person :: getdata ( );
cout<<"\nEnter the
designation and salary :";
gets( designation ) ;
cin >> salary ;
}
void putdata ( )
{
cout
<<"\nDesignation :";
puts( designation ) ;
cout <<"\nSalary :"<<salary ;
Person :: putdata ( );
}
};
class
Manager : public Employee
{
float allowance ;
public :
void getdata ( )
{
Employee :: getdata ( );
cout <<"\nEnter
allowance :";
cin >>allowance ;
}
void putdata ( )
{
Employee :: putdata ( ) ;
cout<<"\nAllowance :"<<allowance ;
}
};
void
main ( )
{
clrscr ( ) ;
Manager obj ;
obj. getdata ( ) ;
cout<<”\n”;
obj. putdata ( ) ;
getch ( );
}
No comments:
Post a Comment