Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
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!"
isset(); is a ------ function.
O a Integer
O b. None
O . Boolean
O d. String
In C Language only
Chapter 14 Solutions
Starting Out with C++: Early Objects (9th Edition)
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
- IN 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_forwardWrite 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_forward
- A palindrome is a string that’s spelled the same way forward and backward. Examples of palindromes include “radar” and “able was i ere i saw elba.” Write a recursive function testPalindrome that returns true if a string is a palindrome, and false otherwise. Note that like an array , the square brackets ( [] ) operator can be used to iteratethrough the characters in a string .arrow_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_forwardIndirect recursion is when function A calls function B, which in turn calls function A. is it true or false.arrow_forward
- Write 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_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
- Recursive Palindrome! Recall that a palindrome is a string that reads the same forward and backward. Write a recursive function is_palindrome (s:str) -> bool to check whether a string s is a palindrome. Here's a hint: think about how you can use is_palindrome(t), where t is a substring of s, to help you decide whether s is a palindrome. Your Answer: 1 # Put your answer here 2 Submitarrow_forwardWrite 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 program that prompts the user to enter a string and displays its reversal.arrow_forwardCodeW For fun X C Solved https://codeworkou... 臺亂 CodeWorkout X272: Recursion Programming Exercise: Is Reverse For function isReverse, write the two missing base case conditions. Given two strings, this function returns true if the two strings are identical, but are in reverse order. Otherwise it returns false. For example, if the inputs are "tac" and "cat", then the function should return true. Examples: isReverse("tac", "cat") -> true Your Answer: 1 public boolean isReverse(String s1, String s2) { 2. if > 3. 4. else if > return true; return false; 5. 6. else { String s1first = String s2last return s1first.equals (s2last) && 51. substring(0, 1); s2, substring(s2.length() 1); 7. 8. 6. isReverse(s1.substring(1), s2.substring(0, s2.length() 1)); { 12} 1:11AM 50°F Clear 12/4/2021arrow_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 LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT