Question

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 letter values.

d. If the word is a Palindrome, print that it is a Palindrome. if not, print that it is not.

If you can use loops then do the problem for any number of characters.

Output Example (input is bold and italicized)

Enter an odd letter word: test

test is not an odd word.

Output Example (input is bold and italicized)

Enter an odd word: kayak

kayak is a palindrome.

Language C++

Homework Answers

Answer #1

CODE

#include <iostream>

using namespace std;

int main() {
    
    string one;
    cout << "Enter an odd word: ";
    cin >> one;

    if(one.length() % 2 == 0)
        cout << one << " is not an odd word.";
    else
    {
        int out = 1, last = one.length() - 1;
        for(int first=0; first < last; first++, last--)
        {
            if(one[first] != one[last])
            {
                out = 0;
                cout << one << " is not a palindrome";
                break;
            }
        }
        if(out == 1)
            cout << one << " is a palindrome";
        
    }
}

OUTPUT

Enter an odd word: kayak
kayak is a palindrome

PLEASE UP VOTE

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
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...
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,...
This is for C++ A string is a palindrome if reverse of the string is same...
This is for C++ A string is a palindrome if reverse of the string is same as the original string. For example, “abba” is palindrome, but “abbc” is not palindrome. Basically a string with a plane of symmetry in the middle of it is considered a palindrome. For example, the following strings are palindromic: "abbbbba", "abba", "abbcbba", "a", etc. For this problem, you have an input string consisting of both lowercase or uppercase characters. You are allowed to pick and...
C++ Language Branching Determine if numbers are equivalent. a) Request two floating point numbers from the...
C++ Language Branching Determine if numbers are equivalent. a) Request two floating point numbers from the console. b) If the numbers are equivalent, output that they are equivalent. c) If the numbers are not equivalent, output the larger number. Example output 1 (input is bold and italicized): Enter two numbers: 10.2 8.5 10.2 is the larger number. Example output 2 (input is bold and italicized): Enter two numbers: 5 5 5 is equivalent to 5.
Create a function in MIPS using MARS to determine whether a user input string is a...
Create a function in MIPS using MARS to determine whether a user input string is a palindrome or not. Assume that the function is not part of the same program that is calling it. This means it would not have access to your .data segment in the function, so you need to send and receive information from the function itself. The program should be as simple as possible while still using necessary procedures. Follow the instructions below carefully. Instructions: ●...
python problem: ( use a loop to read each character from the string and insert into...
python problem: ( use a loop to read each character from the string and insert into the stack) 1. The function main a5.py continually asks the user for a string, and calls isPalindrome to check whether each string is a palindrome. A palindrome is a word or sequence that reads the same backward as forward, e.g., noon, madam or nurses run. 2. Your function must ignore spaces: when the user enters 'nurses run', the function returns True, to indicate that...
Create program that sorts words of a string based on first letter of each word. Use...
Create program that sorts words of a string based on first letter of each word. Use C programming language. - Only use stdio.h and string.h - Remove any newline \n from input string - Use insert function - Input prompt should say "Enter string of your choice: " - Output should print sorted string on new line Example:     Enter string of your choice: this is a string     a is string this
There are two ways to write loops: (1) iterative, like the for-loops we're used to using,...
There are two ways to write loops: (1) iterative, like the for-loops we're used to using, and (2) recursive. Your prerequisite preparation for this course should have exposed you to both, although your working knowledge of recursive loops may not be as strong as that of iterative loops. Consider the following iterative function that prints an array of characters backward: #include <iostream> #include <cstring> // print an array backwards, where 'first' is the first index // of the array, and...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...
Please follow ALL the instructions and solve it by C++. Please and thank you! There are...
Please follow ALL the instructions and solve it by C++. Please and thank you! There are two ways to write loops: (1) iterative, like the for-loops we're used to using, and (2) recursive. Your prerequisite preparation for this course should have exposed you to both, although your working knowledge of recursive loops may not be as strong as that of iterative loops. Consider the following iterative function that prints an array of characters backward: #include <iostream> #include <cstring> // print...