Question

A palindrome is a word or a phrase that is the same when read both forward...

A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome.

Ex: If the input is:

bob

the output is:

bob is a palindrome

Ex: If the input is:

bobby

the output is:

bobby is not a palindrome

IN C++ PLEASE!

Homework Answers

Answer #1
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int main() {
    string data, reversed, modified;
    char ch;
    getline(cin, data);
    for (int i = 0; i < data.size(); ++i) {
        ch = tolower(data[i]);
        if (isalnum(ch)) {
            modified += ch;
            reversed = ch + reversed;
        }
    }
    if (reversed == modified)
        cout << data << " is a palindrome" << endl;
    else
        cout << data << " is not a palindrome" << endl;
    return 0;
}

Know the answer?
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
Similar Questions
A palindrome is a word or a phrase that is the same when read both forward...
A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome. user_string = input() low = 0 high = len(user_string)-1 result = True while low < high: if (user_string[low] == ' '): low += 1 elif (user_string[low]!=user_string[high]): result = False break low +=...
create a program in c++ to determine whether any 5-letter word is a palindrome. Palindromes are...
create a program in c++ to determine whether any 5-letter word is a palindrome. Palindromes are words or sentences that read the same backward or forward. For example, “kayak” is a palindrome while “meter” is not. Ask the user to input 5 characters. You will need five separate variables to store these five characters. After obtaining the characters, compare the characters to determine if the word is a palindrome and output an appropriate message. Ex: Please enter 5 letters: h...
1. A Palindrome is a word that is the same backwards as it is forwards. For...
1. A Palindrome is a word that is the same backwards as it is forwards. For example, the words kayak and madam are Palindromes. a. Request an 5 character value from the console. b. If the input string is not 5 characters, print that the word is not a 5 character word and exit. c. If the input string is 5 characters, determine if the word is or is not a Palindrome. Hint: String indexes can be used to compare...
Write a program that determines whether an input string a palindrome; that is whether it can...
Write a program that determines whether an input string a palindrome; that is whether it can be read the same way forward and backward. At each point, you can read only one character of the input string; do not use an array to first store this string and then analyze it (except, possibly in a stack implementation). Consider using multiple stacks. PLEASE PROVIDE A PSEUDOCODE
Java Please [(1)] A palindrome is a string that reads the same forwards as backwards. Using...
Java Please [(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate [(2)] Let Q be a non-empty queue,...
Demonstrate your continuous progress in learning MIPS assembly by writing and executing the program below. Edit...
Demonstrate your continuous progress in learning MIPS assembly by writing and executing the program below. Edit the program using your favorite code editor (e.g. Notepad++) and load the programs into QtSpim for execution. Activity Directions: Write a program that will read a line of text and determine whether or not the text is a palindrome. A palindrome is a word or sentence that spells exactly the same thing both forward and backward. For example, the string “anna” is a palindrome,...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing associated with the assignment it is failing one part of testing.   Below is the test that fails: Failed test 4: differences in output arguments: -c input data: a b c -c expected stdout: b observed stdout: a b expected stderr: observed stderr: ./test: invalid option -- 'c' Unsure where I have gone wrong. MUST BE WRITTEN IN C++ Task Level 1: Basic operation Complete...
Instructions​: You will find a file named findingNemo.m and another named nemo.txt. The first contains code...
Instructions​: You will find a file named findingNemo.m and another named nemo.txt. The first contains code which will read in strings from nemo.txt, then call Lab08(string) on each line of nemo.txt. Your job is to write Lab08.m. The Lab08 function will take in a string as input and will return an integer n as output. The value of n will be the nth word in the input string, where n is the location of the substring 'Nemo'. Please note that...
please can you make it simple. For example using scanner or hard coding when it is...
please can you make it simple. For example using scanner or hard coding when it is a good idea instead of arrays and that stuff.Please just make one program (or class) and explain step by step. Also it was given to me a txt.htm 1.- Write a client program and a server program to implement the following simplified HTTP protocol based on TCP service. Please make sure your program supports multiple clients. The webpage file CS3700.htm is provided. You may...
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...