Sunteți pe pagina 1din 5

Practical No.

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()
{

long int i=1,fact=1;


while(i<=a)
{
fact=fact*i;
i++;
}
cout<<"\n the factorial is:"<<fact;
}
void Demo::isPalindrome()
{
int sum=0,temp,x;
temp=a;
while(temp>0)
{
x=temp%10;
temp=temp/10;
sum=sum*10 + x;
}
if(sum==a)
{
cout<<"\n It is Palindrome";
}
else
{
cout<<"\n It is Not Palindrome";

}
}
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:

S-ar putea să vă placă și