STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
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.
- Do until the user enters “ENTER” key using “while” condition.
- 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.
- Check if the value of “lower” is greater than “upper”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
3. A palindrome is a sentence that contains the same sequence of letters read-ing it either forwards or backwards. A classic example is "Able was I, ere
I saw Elba." Write a recursive function that detects whether a string is a palindrome. The basic idea is to check that the first and last letters of the
string are the same letter; if they are, then the entire string is a palindrome if everything between those letters is a palindrome.
There are a couple of special cases to check for. If either the first or last character of the string is not a letter, you can check to see if the rest
of the string is a palindrome with that character removed. Also, when you compare 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 and then tells whether or not it is a palindrome. Here's another classic for
testing: "A man, a plan, a canal, Panama!"
Don't copy. Posted answer is wrong
isset(); is a ------ function.
O a Integer
O b. None
O . Boolean
O d. String
Chapter 14 Solutions
STARTING OUT WITH C++ MPL
Ch. 14.1 - What is a recursive functions base case?Ch. 14.1 - What happens if a recursive function does not...Ch. 14.1 - Prob. 14.3CPCh. 14.1 - What is the difference between direct and indirect...Ch. 14 - What type of recursive function do you think would...Ch. 14 - Which repetition approach is less efficient; a...Ch. 14 - When should you choose a recursive algorithm over...Ch. 14 - Prob. 4RQECh. 14 - Prob. 5RQECh. 14 - Prob. 6RQE
Ch. 14 - Predict the Output 7. What is the output of the...Ch. 14 - Soft Skills 8. Programming is communication; the...Ch. 14 - Prob. 1PCCh. 14 - Recursive Conversion Convert the following...Ch. 14 - Prob. 3PCCh. 14 - Recursive Array Sum Write a function that accepts...Ch. 14 - Prob. 5PCCh. 14 - Recursive Member Test Write a recursive Boolean...Ch. 14 - Prob. 7PCCh. 14 - Prob. 8PCCh. 14 - Ackermanns Function Ackermanns function is a...Ch. 14 - Prefix to Postfix Write a program that reads...Ch. 14 - Prob. 11PCCh. 14 - Prob. 12PC
Knowledge Booster
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
- c++ A palindrome is a string that reads the same both forward and backward. For example, the string "madam" is a palindrome. Write a program that uses a recursive function to check whether a string is a palindrome. Your program must contain a value-returning recursive function that returns true if the string is a palindrome and false otherwise. Do not use any global variables; use the appropriate parameter.arrow_forwardIn C Language onlyarrow_forwardIN C LANGUAGE it must ignore spaces and ohter symbols. when checking the input the code must ignore the case-sensitive of letters please apply a copyable codearrow_forward
- Write a recursive function to print all the permutations of a string. For example, for the string abc, the printout is:abcacbbacbcacabcba(Hint: Define the following two functions. The second function is a helper function.def displayPermuation(s):def displayPermuationHelper(s1, s2): The first function simply invokes displayPermuation(" ", s). The secondfunction uses a loop to move a character from s2 to s1 and recursively invokes t with a new s1 and s2. The base case is that s2 is empty and prints s1 to the console.)Write a test program that prompts the user to enter a string and displays all its permutations.arrow_forwardpython codearrow_forwardWrite a recursive function (no auxiliary functions, for/while loops, STL containers or functions, static/global variables) bool mirrorMirrorOnTheWall(string n); Given a string, recursively determine if the string is the same forwards and backwards. mirrorMirrorOnTheWall(""); mirrorMirrorOnTheWall("a"); mirrorMirrorOnTheWall("mirror"); // returns false mirrorMirrorOnTheWall("racecar"); // returns true // returns true // returns true Edit View Insert Format Tools Table 12pt v Paragraph v BIU ...arrow_forward
- Indirect recursion is when function A calls function B, which in turn calls function A. is it true or false.arrow_forwardS is a set of strings recursively defined as follows. Base case: Every variable from the set {a, b, c, d, e, f} is in S. Recursive rules: If x = S and y = S, then: 1. (x + y) Є S 2. x.yЄ S Indicate which expressions are in S. ☐ (d.e.a) a+b a.b.c ☐ (a + d).earrow_forwardWrite a recursive function that displays a string reversely on the console using the following header: def reverseDisplay(value):For example, reverseDisplay("abcd") displays dcba. Write a test programthat prompts the user to enter a string and displays its reversal.arrow_forward
- In C++ Write a recursive function that displays a string reversely on the console using the following header:void reverseDisplay(const string& s) For example, reverseDisplay("abcd") displays dcba. Write a test programthat prompts the user to enter a string and displays its reversal.arrow_forwardA palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes:Able was I, ere I saw ElbaA man, a plan, a canal, PanamaDesserts, I stressedKayakWrite a bool function that uses recursion to determine if a string argument is a palindrome. The function should return true if the argument reads the same forward andbackward. Demonstrate the function in a program.arrow_forwardA 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!"arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning