EBK STARTING OUT WITH C++
9th Edition
ISBN: 9780134379371
Author: MUGANDA
Publisher: PEARSON CUSTOM PUB.(CONSIGNMENT)
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
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".
Chapter 14 Solutions
EBK STARTING OUT WITH C++
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
- A palindrome is a string that reads the same both forward and backward. For example, the string "madam" is a palandrome. Write a program that uses a recursive function to check whether a string is a palindrome. Yourprogram must contain a value returning recursive function that returns true is the string is a palindrome andfalse otherwise. Do not use any global variables; use the appropriate parameters.arrow_forwardA recursive function typically has two components: one that provides a means for the recursion to terminate by testing for a(n)____________ case, and one that expresses the problem as a recursive call for a slightly simpler problem than the original call.arrow_forwardIndirect recursion is when function A calls function B, which in turn calls function A. is it true or false.arrow_forward
- language: Python Problem: Write a recursive function reverse(sentence) for reversing a sentence. For example, reverse('Who let the dogs out?') will return '?tuo sgod eht tel ohW'. Also write a test case in the program to prove the function given works.arrow_forward(C Language) Write a recursive function called DigitCount() that takes a non-negative integer as a parameter and returns the number of digits in the integer. Hint: The digit count increases by 1 whenever the input number is divided by 10.arrow_forwardWrite a recursive function recursiveMinimum that takes an integer array, a starting subscript, and an ending subscript as arguments, and returns the smallest element of the array. The function should stop processing and return when the starting sub- script equals the ending subscript. c++arrow_forward
- Define a recursive function removeAll that expects an item and a Lisp-like list as arguments. This function returns a Lisp-like list with all of the instances of the item removed. In the lisplist.py file, make sure to include the insert() and equal() methods from Programming exercise 9.7 and Programming exercise 9.8. Hint: Keep on removing the item if it equals the list’s first item. Here is an example of its use: >>> lyst = cons(2, cons(2, (cons 3, THE_EMPTY_LIST))) >>> lyst (2 2 3) >>> removeAll(2, lyst) (3) >>> removeAll(3, lyst) (2 2) File: lisplist.py Project 9.9 Adds a removeAll function for Lisp lists. Add the insert() and equal() methods from Programming Exercise 9.7 and 9.8 """ class Node(object): """Represents a singly linked node.""" def __init__(self, data, next = None): self.data = data self.next = next def __repr__(self): """Returns the string representation of a nonempty lisp list."""…arrow_forwardPythonDesign a recursive function that accepts an integer argument, n, and prints the number 1 up through n.arrow_forwardWrite a Lisp function called reverse that recursively reverses a string. In order to put the recursive call at the end of the function, do it this way: concatenate the last character in the string with the result of making a recursive call and sending everything *but* the last letter. Test your function with this code and paste both the code and the output into the window (reverse "")(reverse "a")(reverse "ab")(reverse "abc")(reverse "abcd")arrow_forward
- Pascal's triangle is a useful recursive definition that tells us the coefficients in the expansion of the polynomial (x + a)^n. Each element in the triangle has a coordinate, given by the row it is on and its position in the row (which you could call a column). Every number in Pascals triangle is defined as the sum of the item above it and the item above it and to the left. If there is a position that does not have an entry, we treat it as if we had a 0 there. *picture of the pascals triangle* Given the following recursive function signature, write the recursive function that takes a row and a column and finds the value at that position in the triangle. Assume that the triangle starts at row 0 and column 0. Examples: pascal(2, 1) -> 2, pascal(1, 2) -> 0 public int pascal(int row, int column) { }arrow_forwardA palindrome is a string that reads the same forwards or backwards; for example dad, mom, deed are palindromes (i.e., reversing a palindrome produces the same string). Use C++ Programing language Write a recursive, boolean-valued function, isPalindrome that takes a string as a parameter and returns whether the string is a palindrome. A string, s, is a palindrome if: s is the empty string or s consists of a single letter (which reads the same back or forward), or the first and last characters of s are the same, and the rest of the string (i.e., the second through next-to-last characters) form a palindrome. Write a test program that reads a string from the standard input device and outputs whether the input string is a palindrome or not.arrow_forwardRecursive Exponentiation (using c language) Write a recursive function power(base, exponent) that when invoked returns baseexponent. For example, power(3, 4) = 3 * 3 * 3 * 3. Assume that exponent is an integer greater than or equal to 1. Then, write a demo program that uses the power function and test it out for a number of inputs. Hint: The recursion step would use the relationship baseexponent = base * baseexponent–1 and the terminating condition occurs when exponent is equal to 1 because base1 = basearrow_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