Check whether the given number is palindrome or
not. Use individual member function to take input, output and display. Use Inheritance or Constructor.
//Program using Constructor
#include<iostream>
using namespace std;
class checkpelindrom
{
int num;
public:
checkpelindrom();
~checkpelindrom();
void view();
};
checkpelindrom :: checkpelindrom()
{
cout<<"Enter the number\n";
cin>>num;
}
checkpelindrom :: ~checkpelindrom()
{
//cout<<"\n\nDestruction";
}
void checkpelindrom :: view()
{
int a ,temp ,rev=0;
temp=num;
while(temp!=0)
{
a=temp%10;
rev=rev*10+a;
temp /=10;
}
if(rev==num)
cout<<"\nIt is a pelindrom number\n\n";
else
cout<<"\nIt is not a pelindrom number\n\n";
}
int main()
{
checkpelindrom cp;
cp.view();
return 0;
}
//Program using Constructor
#include<iostream>
using namespace std;
class checkpelindrom
{
int num;
public:
checkpelindrom();
~checkpelindrom();
void view();
};
checkpelindrom :: checkpelindrom()
{
cout<<"Enter the number\n";
cin>>num;
}
checkpelindrom :: ~checkpelindrom()
{
//cout<<"\n\nDestruction";
}
void checkpelindrom :: view()
{
int a ,temp ,rev=0;
temp=num;
while(temp!=0)
{
a=temp%10;
rev=rev*10+a;
temp /=10;
}
if(rev==num)
cout<<"\nIt is a pelindrom number\n\n";
else
cout<<"\nIt is not a pelindrom number\n\n";
}
int main()
{
checkpelindrom cp;
cp.view();
return 0;
}