Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Programming Description The challenge for this second assignment is to devel

ID: 2247190 • Letter: C

Question

C++ Programming

Description The challenge for this second assignment is to develop a program, called palindrome.cpp, capable of detecting palindromes. A palindrome is a word, phrase, or sequence that reads the same backward as forward. Your program should take input from stdin and determine whether the characters formulate a palindrome Requirements The following functions should be defined: isPalindrome (string text) Example: s ./palindrome Enter Text: bob The word "bob" is a palindrome. Enter Text: A car, a man, a maraca The phrase "A car, a man, a maraca" is a palindrome Enter Text: slow The word "slow" is not a palindrome. Enter Text: quit

Explanation / Answer

#include <bits/stdc++.h>
using namespace std;

bool isPalindrom(string str){
  
int r=str.length()-1;
int l=0;
while(l<r){
if(str[l++]!=str[r--])
return false;
}
  
return true;
}
int main() {
string str;
cin>>str;
// str="abaa";
if(isPalindrom(str))
cout<<"The Word "<<str<<" is palindrom";
else cout<<"The Word "<<str<<" is not palindrom";
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote