Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 20, Problem 2PC
Program Plan Intro
Recursive conversion
Program Plan:
- Include the required header files.
- Declare the necessary function prototype and constants.
- Define the main () function.
- Declare the necessary variables to get the input.
- Get the required input from the user.
- Call the method “sign()” to indicate the sign.
- User input gets validated and call the function recursively for the user given input.
- Define the “sign()” method
- Declare the necessary variables
- Validates the value given by the user using “if” statement.
- If the condition becomes true, it will call the function recursively for the number of times based on the input provided by the user.
- If the condition becomes false, it gets returned to the “main()” method.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Consider the following function:
void fun_with_recursion(int x) { printf("%i\n", x); fun_with_recursion(x + 1); } What will happen when this function is called by passing it the value 0?
For glass box testing of a recursive function, you should test cases where:
a) the function returns without a recursive call, ie using a base case
b) the function makes exactly one recursive call
c) the function makes more than one recursive call
d) all of these
For any part that requires recursion, if you do not create a
recursive function, that will result in a
on that part.
Chapter 20 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 20.2 - What happens if a recursive function never...Ch. 20.2 - What is a recursive functions base case?Ch. 20.2 - Prob. 20.3CPCh. 20.2 - What is the difference between direct and indirect...Ch. 20 - What is the base case of each of the recursive...Ch. 20 - What type of recursive function do you think would...Ch. 20 - Which repetition approach is less efficient, a...Ch. 20 - When should you choose a recursive algorithm over...Ch. 20 - Explain what is likely to happen when a recursive...Ch. 20 - The _____________ of recursion is the number of...
Ch. 20 - Prob. 7RQECh. 20 - Prob. 8RQECh. 20 - Prob. 9RQECh. 20 - Write a recursive function to return the number of...Ch. 20 - Write a recursive function to return the largest...Ch. 20 - #include iostream using namespace std; int...Ch. 20 - Prob. 13RQECh. 20 - #include iostream #include string using namespace...Ch. 20 - Iterative Factorial Write an iterative version...Ch. 20 - Prob. 2PCCh. 20 - Prob. 3PCCh. 20 - Recursive Array Sum Write a function that accepts...Ch. 20 - Prob. 5PCCh. 20 - Prob. 6PCCh. 20 - Prob. 7PCCh. 20 - Prob. 8PCCh. 20 - Prob. 9PCCh. 20 - Prob. 10PCCh. 20 - Prob. 11PCCh. 20 - 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
- Write a recursive function that converts a decimal number into a binary number as a string. The function header is: string decimalToBinary(int value) Write a test program that prompts the user to enter a decimal number and dis- plays its binary equivalent.arrow_forwardRecursive ConversionConvert the following function to one that uses recursion.void sign(int n){while (n > 0)cout << "No Parking\n";n−−;}Demonstrate the function with a driver program.arrow_forwardMULTIPLE FUNCTIONS AND RECURSIVE FUNCTIONS Use #include<stdio.h> Implement the picture shown below.arrow_forward
- Recursive Sum! Write a recursive function rc_sum(n:int) -> int that returns the sum of the first n positive integers. The function should look very similar to the factorial function you have seen before. Your Answer: 1 # Put your answer here 2 Submitarrow_forwardWrite a recursive function that displays the number of even and odd digits in an integer using the following header: void evenAndOddCount(int value) Write a test program that prompts the user to enter an integer and displays the number of even and odd digits in it.arrow_forwardCreate a recursive function that simulates the range function. For example: Enter the range (begin, end, increment) separated by spaces: 3 15 3 [3,6,9,12]arrow_forward
- Write a recursive function definition for the following function: int squares(int n); //Precondition: n >= 1 //Returns the sum of the squares of numbers 1 through n. For example, squares(3) returns 14 because 12 + 22 + 32 is 14.arrow_forwardMULTIPLE FUNCTIONS AND RECURSIVE FUNCTIONS.arrow_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_forward
- lint power (int base, int exponent); Define the recursive function power() that when invoked returns baseonent Assume that exponent is an integer greater than or equal to 1. Hint: The recursion step would use the relationship basenent = base * baseonert- and the terminating condition occurs when exponent is equal to 1 because base' = base or when exponent is equal to o because base = 1.arrow_forwardRecursive PrintingDesign a recursive function that accepts an integer argument,n , and prints the numbers 1 up through n .arrow_forwardWrite a recursive function that converts a decimal number to binary number.int DecToBin(int dec);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