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 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
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...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
is there anything wrong with the solution. the question are from java course Write a main...
is there anything wrong with the solution. the question are from java course Write a main method that will request the user to enter Strings using a JOptionPane input dialog. The method should continue accepting strings until the user types “STOP”.       Then, using a JOptionPane message dialog, tell the user how many of the strings begin and end with a digit. Answer: import javax.swing.*; public class IsAllLetters {     public static void main(String[] args) {         String input;         int count =...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT