Documente Academic
Documente Profesional
Documente Cultură
1(c)
Design the class Demo which will contain the following methods:
readNo() ,factorial() for calculating the factorial of a number, isPalindrome()
will check the given number is palindrome, isArmstrong() which will
calculatethe given number is armStrong or not, reverseNo() will reverse the
given number.
Code:
#include<iostream.h>
#include<conio.h>
class Demo
{
long int a;
public:
void readno();
void Factorial();
void ReverseNo();
void isPalindrome();
void Armstrong();
};
void Demo::readno()
{
cout<<"\n Enter the no:";
cin>>a;
}
void Demo::Factorial()
{
}
}
void Demo::Armstrong()
{
int temp,d,arm=0;
temp=a;
while (temp > 0)
{
d=temp%10;
temp=temp/10;
arm=arm +(d*d*d);
}
if(arm==a)
{
cout<<"\n It is Armstrong";
}
else
{
cout<<"\n It is Not Armstrong";
}
}
void Demo::ReverseNo()
{
long int sum=0,m=0;
while(a!=0)
{
m=a%10;
sum=m+sum*10;
a=a/10;
}
cout<<"\n the Revese No is"<<sum;
}
void main()
{
cout<<"\n\t\t Welcome To the Class Demo";
cout<<"\n";
g.readno();
cout<<"\n";
g.Factorial();
cout<<"\n";
g.isPalindrome();
cout<<"\n";
g.Armstrong();
cout<<"\n";
g.ReverseNo();
}
Output: