Starting Out with C++ from Control Structures to Objects (8th Edition)
8th Edition
ISBN: 9780133769395
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 19, Problem 11PC
Program Plan Intro
Palindrome detector
Program Plan:
- Include the required header files.
- Declare and define the necessary function prototype.
- Define the main () function.
- Declare and define the necessary variables for storing strings.
- Get the required input from the user.
- Call the method “isPalindrome ()” to validate whether the given string is a palindrome or not.
- Define the “isPalindrome ()” function
- Declare the necessary variables.
- Condition to validate whether the given length of string is “1” to return the given string is a palindrome.
- Use condition statement to validate whether the length of the string is greater than one.
- If the condition becomes true, then the given string is reversed to find whether the given string is a palindrome or not.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Recursive Power FunctionWrite a function that uses recursion to raise a number to a power. The function should accept two arguments: the number to be raised and the exponent. Assume that the exponent is a nonnegative integer. Demonstrate the function in a program.
SAMPLE RUN #0: ./recursiveExponent
Hide Invisibles
Highlight: Show Highlighted Only
2^3=8↵ 2^4=16↵ 3^3=27↵ 6^3=216↵ 7^7=823543↵ 10^9=1000000000↵
Recursive PrintingDesign a recursive function that accepts an integer argument,n , and prints the numbers 1 up through n .
Instructions:
In the code editor, you are provided with a main() function that asks the user for a string and passes this string and the size of this string to a function call of the function, preserveString().
This preserveString() function has the following description:
Return type - void
Name - preserveString
Parameters
The string
Length of the string
Description - this is a recursive function that prints the string repeatedly. Each time it prints the string, it excludes the last character of the string until only one character is left.
This preserveString() function has already been partially implemented. Your only task is to add the recursive case of this function.
Please Finish the code ASAP:
This is my current given code:
#include<stdio.h>#include<string.h>
#define STR_MAX_SIZE 100
void preserveString(char*, int);
int main(void) { char str[STR_MAX_SIZE];
printf("Enter string: "); fgets(str, STR_MAX_SIZE, stdin);
preserveString(str,…
Chapter 19 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
Ch. 19.2 - What happens if a recursive function never...Ch. 19.2 - What is a recursive functions base case?Ch. 19.2 - Prob. 19.3CPCh. 19.2 - What is the difference between direct and indirect...Ch. 19 - What is the base case of each of the recursive...Ch. 19 - What type of recursive function do you think would...Ch. 19 - Which repetition approach is less efficient, a...Ch. 19 - When should you choose a recursive algorithm over...Ch. 19 - Explain what is likely to happen when a recursive...Ch. 19 - The _____________ of recursion is the number of...
Ch. 19 - Prob. 7RQECh. 19 - Prob. 8RQECh. 19 - Prob. 9RQECh. 19 - Write a recursive function to return the number of...Ch. 19 - Write a recursive function to return the largest...Ch. 19 - #include iostream using namespace std; int...Ch. 19 - Prob. 13RQECh. 19 - #include iostream #include string using namespace...Ch. 19 - Iterative Factorial Write an iterative version...Ch. 19 - Prob. 2PCCh. 19 - Prob. 3PCCh. 19 - Recursive Array Sum Write a function that accepts...Ch. 19 - Prob. 5PCCh. 19 - Prob. 6PCCh. 19 - Prob. 7PCCh. 19 - Prob. 8PCCh. 19 - Prob. 9PCCh. 19 - Prob. 10PCCh. 19 - Prob. 11PCCh. 19 - Ackermanns Function Ackermanns Function is a...
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
- CodeWorkout Gym Course Search exercises... Q Search kola shreya@columbus X275: Recursion Programming Exercise: Check Palindrome X275: Recursion Programming Exercise: Check Palindrome Write a recursive function named checkPalindrome that takes a string as input, and returns true if the string is a palindrome and false if it is not a palindrome. A string is a palindrome if it reads the same forwards or backwards. Recall that str.charAt(a) will return the character at position a in str. str.substring(a) will return the substring of str from position a to the end of str,while str.substring(a, b) will return the substring of str starting at position a and continuing to (but not including) the character at position b. Examples: checkPalindrome ("madam") -> true Your Answer: 1 public boolean checkPalindrome (String s) { 4 CodeWorkout © Virginia Tech About License Privacy Contactarrow_forwardCyclops numbersdef is_cyclops(n):A nonnegative integer is said to be a cyclops number if it consists of an odd number of digits so that the middle (more poetically, the “eye”) digit is a zero, and all other digits of that number are nonzero. This function should determine whether its parameter integer n is a cyclops number, and return either True or False accordingly n Expected result 0 True 101 True 98053 True 777888999 False 1056 False 675409820 Falsearrow_forwardCodeWorkout Gym Course Search exercises... Q Search kola shreya@colum X459: Review- Fibonacci In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, characterized by the fact that every number after the first two is the sum of the two preceding ones: e, 1, 1, 2, 3, 5, 8, 13, Write a recursive function that the returns the nth fibonacci number. Examples: fibonacci(0) -> 0 fibonacci(1) -> 1 fibonacci(7) -> 13 Your Answer: 1 public int fibonacci(int n) { 2 3} 4 CodeWorkout © Virginia Tech About License Privacy Contactarrow_forward
- Question 1 Not complete Marked out of 1.00 Flag question Write a recursive function named count_non_digits (word) which takes a string as a parameter and returns the number of non-digits in the parameter string. The function should return 0 if the parameter string contains only digits. Note: you may not use loops of any kind. You must use recursion to solve this problem. You can assume that the parameter string is not empty. For example: Test Result print(count_non_digits ('123')) print(count_non_digits ('2rPTy5')) print(count_non_digits ('hello world')) 11 Precheck Check 0 4 Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %) 1arrow_forwardJAVA CODE ONLY AND PROVIDE OUTPUT SCREENSHOT PLEASEarrow_forwardDesign a function that accepts a list of numbers as an argument. The function should recursively calculate the sum of all the numbers in the list and return that valarrow_forward
- Write a recursive function that parses a hex number as a string into a decimal integer. The function header is: int hexToDecimal(const string& hexString) Write a test program that prompts the user to enter a hex string and displays its decimal equivalent.arrow_forwardWrite a recursive function to return the total number of space characters in a string. You need to define the following two functions. The second one is a recursive helper function. int numberOfSpaces(const string& s) int numberOfSpaces(const string& s, int i) Write a test program that prompts the user to enter a string, invokes the function, and displays the number of spaces in the string.arrow_forwardJAVA CODE PLEASE Recursive Functions Quiz by CodeChum Admin Create a recursive function named sequence that accepts an integer n. This function prints the first n numbers of the Fibonacci Sequence separated by a space in one line Fibonacci Sequence is a series of numbers in which each number is the sum of the two preceding numbers. In the main function, write a program that accepts an integer input. Call the sequence function by passing the inputted integer. Input 1. One line containing an integer Output Enter·a·number:·5 0·1·1·2·3arrow_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 - CONSIGNMENTC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
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
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,