Thursday 26 September 2013

Question of glass and object

/*
     Question : Define a class Number , which contains the data member num and
          functions ,
              * read the number
              * display the number
              * reverse the number
              * check whether the number is palindrome or not
              * check whether the number is armstrong or not

*/

#include<iostream.h>
#include<conio.h>
class Number
{
     int num;
     public:
          void readNum()
          {
cout<<endl<<"Enter the number :";
              cin>>num;
          }
          void showNum()
          {
cout<<endl<<"Number ="<<num;
          }
          int reverse();
          void palindrome();
          void armstrong();
};
int Number::reverse()
{
     int num2=num;
     int rev=0;
     while(num2!=0)
     {  
          rev=rev*10+num2%10;
          num2=num2/10;
     }
     return rev;
}
void Number::palindrome()
{
     int rev;

     rev=reverse();

     if(rev==num)
          cout<<endl<<"Palindrome";
     else
          cout<<endl<<"Not Palindrome";
}

void Number::armstrong( )
{
     int num2=num;

     int sum=0;

     int a;

     while(num2!=0)
     {
          a=(num2%10);
    
          sum=sum+a*a*a;

          num2=num2/10;
     }

     if(sum==num)
          cout<<endl<<"Armstrong";
     else
          cout<<endl<<"Not Armstrong";

}

void main()
{
     Number ob;
int num;
     ob.readNum();

     ob.showNum();
    num=ob.reverse();
cout<<”Reverse=”<<num;
     ob.palindrome();
     ob.armstrong();

     getch();

No comments:

Post a Comment