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 9PC
Program Plan Intro
String Reverser
Program Plan:
- Include the required header files.
- Declare the necessary function prototype and constants.
- Define the main () function.
- Declare the necessary variables.
- Get the required input from the user.
- Call the method “reversestring()” to reverse the string.
- Display the string after reversing.
- Define the “reversestring ()” method,
- Condition that validates the length of the string, if the length of the string is less than “0” it gets returned as an empty string.
- If the length of the string is greater than “0”, then given string gets reversed and will be displayed.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Recursive PrintingDesign a recursive function that accepts an integer argument,n , and prints the numbers 1 up through n .
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↵
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_forwardPython Language Prime funcationarrow_forwardPYTHON CS1 PROBLEM (NO LOOPS) Define a recursive function that takes two strings str1 and str2 as parameters. It returns True if str1 is a suffix of str2, otherwise it should return False.For example: If str1 = True. If str1 = False. If str1 = If str1 = If str1 = If str1 = “washer” and str2 = “dishwasher” then your function should return “wash” and str2 = “dishwasher” then your function should return “” and str2 = “test” then your function should return True. “test” and str2 = “” then your function should return False.“” and str2 = “” then your function should return True.“test” and str2 = “test” then your function should return True.arrow_forward
- Computer science C prog Create a recursive function that finds if a number is palindrome or not(return true or false), A palindromic number is a number (such as 16461) that remains the same when its digits are reversed. In the main function asks the user to enter a number then check if it's palindrome or not using the function you created previously.arrow_forwardC PROGRAMarrow_forwardQuestion 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_forward
- CodeWorkout 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_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
- Don't copy. Posted answer is wrongarrow_forwardExercise Objectives Problem Description Write a program that reads a string and mirrors it around the middle character. Examples: abcd becomes cdab. abcde becomes deCab AhmadAlami becomes AlamiAhmad Page 1 of 2 Your program must: • Implement function void reflect (char* str) which receives a string (array of characters) and mirrors it. This function does not print anything. • Read from the user (in main()) a string and then print the string after calling function reflect(). • Use pointers and pointer arithmetic only. The use of array notation and/or functions from the string.h library is not allowed.arrow_forwardPython Language Useful websites: : http://en.wikipedia.org/wiki/Radix http://www.purplemath.com/modules/numbbase.htm Special Rules: Use only Boolean/math expressions and conditional statements (if-statements). Do not use built-in functions for converting integers into a string representation. Here to start with: kthDigit(x: int, b: int, k: int) -> int .........arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning