2. Write a CPP program to find the given string is palindrome or not. Declare private member function to find palindrome of the given string and access it using public member function.

 /* PALINDROME */


#include<iostream>

#include<string>

class palinstr

{

            char string[30];

            int checkpalin(char *);

  public:

            void palin();

};

void palinstr::palin()

{

            cout<<"Enter a String: ";

            cin>>string;

            if(checkpalin(string))                              

                        cout<<string<<" is a Palindrome\n";

            else

            cout<<string<<" is not a Palindrome\n";

}

int palinstr::checkpalin(char string[])

{

            int length,i;

            length=strlen(string);

            for(i=0; i< length/2; i++)

                        if(string[i]!=string[length-1-i])

                                    return 0;

            return 1;

}

int main()

{

            palinstr sp;

            sp.palin();

}
Posted by Unknown On 01:48 No comments

0 comments:

Post a Comment

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Blog Archive

Contact Us


Name

E-mail *

Message *