#include<iostream.h>
#include<conio.h>
#include<math.h>
class number
{
protected:
int num;
public:
void getnum();
int NUM;
};
class cube : public number
{
protected:
int res;
public:
void cubenum();
};
class amstrong : public cube
{
public:
void amsnum();
};
void number :: getnum()
{
cout<<"\nEnter a number:";
cin>>num;
NUM=num;
}
void cube :: cubenum()
{
res=0;
int rem;
while(num!=0)
{
rem=num%10;
res=res+pow(rem,3);
num=num/10;
}
}
void amstrong :: amsnum()
{
if(res==NUM)
cout<<"\nThe Number "<<NUM<<"is an amstrong number\n";
else
cout<<"\nThe Number "<<NUM<<"is not an amstrong number\n";
}
void main()
{
clrscr();
amstrong a;
cout<<’\n\t\t MULTI-LEVEL INHERITANCE\n”;
a.getnum();
a.cubenum();
a.amsnum();
getch();
}
Comments
Post a Comment