Question
C++ Check if string is a palindrome Goal of the code: Write a function to verify if a word is a palindrome or not. A
C++ Check if string is a palindrome
Goal of the code: Write a function to verify if a word is a palindrome or not. A palindrome is a word that reads the same backward as it does forward. Example: "madam"
Input: The input will be a single string with no spaces. Output: If the word is a palindrome, print to the console "Is a palindrome". If the word is not a palindrome, print to the console "Not a palindrome"
Template to follow and complete :
#include
bool validPalindrome( std::string str ){ // This problem is very similar to the reverse array problem. Remember that strings support the [] operator. // Use two pointers, one starts at the beginning and one at the end of the string. // Use the length() function to get the size of the string. // Traverse the string while incrementing the first pointer, and decrementing the second. }
int main() {
// Initialize a string // Read the input into the string, just use std::cin. No need to use std::getline() since we don't have spaces or multiple words
// Check if the string is a plaindrome and print the appropriate answer std::cout << std::endl; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started