Starting out With C++, Early Objects - Access
Starting out With C++, Early Objects - Access
8th Edition
ISBN: 9780133452259
Author: GADDIS
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 14, Problem 8PC
Program Plan Intro

Palindrome Testing

Program Plan:

  • Include the required header files to the program.
  • Declare function prototype.
  • Define the “main()” function. Inside this function,
    • Do until the user enters “ENTER” key using “while” condition.
      • Get a word from the user and store it in a variable “word”.
      • Check if the entered word is empty.
        • If the condition is true then, return 1.
      • Call the function “isPalindrome()” and check if the function returns “true”.
        • If the function returns true then, the entered word is a palindrome.
        • Else, the entered word is not a palindrome.
    • Return the statement.
  • Give function definition for “isPalindrome()”.
    • Check if the value of “lower” is greater than “upper”.
      • Return “true”.
    • Check if the first and the last characters are not equal.
      • Return “false”.
    • Return and call the function “isPalindrome()” recursively.

Blurred answer
Students have asked these similar questions
A palindrome is a sentence that contains the same sequence of letters reading it either forwards or backwards. A classic example is '1\.ble was I, ereI saw Elba." Write a recursive function that detects whether a string is apalindrome. The basic idea is to check that the first and last letters of thestring are the same letter; if they are, then the entire string is a palindromeif everything between those letters is a palindrome.There are a couple of special cases to check for. If either the first orlast character of the string is not a letter, you can check to see if the restof the string is a palindrome with that character removed. Also, when youcompare letters, make sure that you do it in a case-insensitive way.Use your function in a program that prompts a user for a phrase andthen tells whether or not it is a palindrome. Here's another classic fortesting: '1\. man, a plan, a canal, Panama!"
For function decToBinary, write the missing parts of the recursion case. This function should return a string that stores the binary equivalent for int variable num. Example: The binary equivalent of 13 may be found by repeatedly dividing 13 by 2. So, 13 in base 2 is represented by the string "1101". Examples: decToBinary(13) -> "1101"   public String decToBinary (int num) {  if (num < 2)    return Integer.toString(num);  else    return <<Missing recursive call>> + <<Missing calculation>>;}
Write a recursive function that takes a positive integer and returns the factorial of that integer. Attention, the function must be recursive, and its name must be "fatorial".
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning