Nov 29, 2014

Check whether the given number is palindrome or not. Use individual member function to take input, output and display. Use Inheritance

#include<iostream>

using namespace std;

class palindrome

{

public:

   void setnum(int n)

    {

        number=n;

    }

     protected: int number;

};

class palnum:public palindrome

    {

    public:

       int temp,rev=0,rem;

void chknum()

    {

temp=number;

while(temp!=0)

{

rem=temp%10;

temp=temp/10;

rev=rev*10+rem;

}

if(rev==number)

cout<<"Yah!! "<<endl<<number<<" is palindrome number"<<endl;

else

cout<<"No ??"<<endl<<number<<" is not palindrome number"<<endl;

}

};

int main()

{

int n;

palnum pal;

cout<<"Enter number to check palindrome or not :";

cin>>n;

pal.setnum(n);

pal.chknum();

return 0;

}

No comments:

Create a Diamond in C++

 #include<iostream> using namespace std; int main() { int i, j, k,r; cout<<"Enter the row of diamond   "; cin>>r...