Question

5- Implement and test the following function: //bool ispalindrome(string s) //return true iff s is a palindrome //For example: ispalindrome(RADAR) return true, ispalindrome (ABCD) returns false. Enter word to find if the word is palindrome: RADAR The word is RADAR a palindrome Press any key to continue Enter word to find if the word is palindrome: ABCDEF The word is ABCDEF is not a palindrome Press any key to continue
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <string>
using namespace std;
//is Pallindrom function to check given string is pallindrom or not
bool isPalindrome(string s){
   int   i=0; //i points to starting charecter
   int j=s.length()-1; //j points to last charecter
   while(i<j){
       //if charecter at i and charecter at jth position not equal it is not a pallindrome
       if(s[i]!=s[j]){
           return false; //not pallindrome
       }
       //updating i,j
       i++;
       j--;
   }
   return true;//pallindrom
}
//main function
int main(){
   string str;
   cout<<"Enter word to find if the word is pallindrome:";
   cin>>str;//taking string

   if(isPalindrome(str)){
       cout<<"The word is "<<str<<" is pallindrome"<<endl;
   }
   else{
       cout<<"The word is "<<str<<" is not pallindrome"<<endl;
   }
}

CProgram Flles (x8bDev-CppyconsolePauser.exe nter word to find if the word is pallindrome RADAR The word is RADAR is pallindr
Add a comment
Know the answer?
Add Answer to:
Implement and test the following function://bool ispalindrome(string s)//return true iff s is a palindrome//For example: ispalindrome("RADAR")...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that uses the function isPalindrome given in Example 6-6 (Palindrome). Test your program...

    Write a program that uses the function isPalindrome given in Example 6-6 (Palindrome). Test your program on the following strings: madam, abba, 22, 67876, 444244, trymeuemyrt Modify the function isPalindrome of Example 6-6 so that when determining whether a string is a palindrome, cases are ignored, that is, uppercase and lowercase letters are considered the same. The isPalindrome function from Example 6-6 has been included below for your convenience. bool isPalindrome(string str) { int length = str.length(); for (int i...

  • Implement a function that returns true if a String is Palindrome or false otherwise. A Palindrome...

    Implement a function that returns true if a String is Palindrome or false otherwise. A Palindrome is a String that reads from right and left the same. An empty String, and a String with one character are Palindrome. public static boolean isPalindrome (String str) {

  • python Problem 3 (Palindrome) Write a function called ispalindrome(string) that takes a string (with spaces) as...

    python Problem 3 (Palindrome) Write a function called ispalindrome(string) that takes a string (with spaces) as argument and returns True if that string (ignoring spaces) is a palindrome. A palindrome is a word or phrase that spells the same thing forwards as backwards (ignoring spaces). Your program should use a recursive process to determine the result, by comparing the first and last letters of the string, and if necessary, calling ispalindrome() on the rest of the string. Sample run: print(ispalindrome('never...

  • For this assignment, you will create a program that tests a string to see if it...

    For this assignment, you will create a program that tests a string to see if it is a palindrome. A palindrome is a string such as “madam”, “radar”, “dad”, and “I”, that reads the same forwards and backwards. The empty string is regarded as a palindrome. Write a recursive function: bool isPalindrome(string str, int lower, int upper) that returns true if and only if the part of the string str in positions lower through upper (inclusive at both ends) is...

  • Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true...

    Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true if that integer is palindrome, otherwise it returns false. The function also prints the digits of the integer in reverse order in which they were found. Write a main) function that reads an integer, calls the function is whether the integer is a palindrome or not. Palindrome), and prints Sample input/output: nter an integer: 23434 nter an integer 23432 3434 is not a palindrome...

  • Python Question: A palindrome is a string that reads identical forwards and backwards. Examples include abba,...

    Python Question: A palindrome is a string that reads identical forwards and backwards. Examples include abba, abcba, a1b1b1a, houstonnotsuoh etc. Your task is to write a function ispalindrome(string) that reads an input string and returns True if both of the following are true: The string is a palindrome The string has at least one letter (uppercase or lowercase) For example: ispalindrome('racecar') should return True PS: ispalindrome('123321') should return False ispalindrome('racecar') should return True

  • (Palindrome integer) Write the functions with the following headers: # Return the reversal of an integer,...

    (Palindrome integer) Write the functions with the following headers: # Return the reversal of an integer, e.g. reverse(456) returns # 654 def reverse(number): # Return true if number is a palindrome def isPalindrome(number): Use the reverse function to implement isPalindrome. A number is a palindrome if its reversal is the same as itself. Write a test program that prompts the user to enter an integer and reports whether the integer is a palindrome.

  • This is for C Programming Write a function that checks whether a given string is a...

    This is for C Programming Write a function that checks whether a given string is a palindrome or not, recursively. Palindrome is a word, phrase, or sequence that reads the same backward as forward. You may not modify the functions signatures, that is, adding any new parameters or changing the data type of the parameters in any way. You may not use square brackets and any type of loops in your solutions. For example: isPalindrome("abcba", ...) -> true isPalindrome("abcb1", ...)...

  • Write a function check palindrome, which takes a string x as argument and which returns True...

    Write a function check palindrome, which takes a string x as argument and which returns True if x is a palindrome, and False otherwise. A palindrome is a word that reads the same backwards as forwards (like for example “racecar”). Your function should be recursive (i.e. call itself) and proceed as follows. 1. If x is a string of length 0 or 1 return True. 2. If the rst and the last letter of x are di erent, return False....

  • Write a recursive method,     public static Boolean isPalindrome(String s) That returns true if s is...

    Write a recursive method,     public static Boolean isPalindrome(String s) That returns true if s is a palindrome, else false.


ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT