Question: TITLE THREE RECURSIVE FUNCTIONS C++ INTRODUCTION Recursion is a programming technique in which a function calls itself. It is another way of implementing repetitive computations,
TITLE
THREE RECURSIVE FUNCTIONS C++
INTRODUCTION
Recursion is a programming technique in which a function calls itself. It is another way of implementing repetitive computations, which we have previously associated with loops. When called to solve a problem, a recursive function passes a smaller version (or versions) of the problem to another instance (or instances) of itself, then uses the results returned by the recursive call or calls to build a solution to the original problem.
DESCRIPTION
Design, implement, and document recursive functions to solve three problems; test those functions by calling them from appropriate main functions; and document the functions.
Throughout, keep in mind the three questions that arise in designing a recursive algorithm:
- What is/are smaller but identical subproblem(s)?
- How will the smaller solution(s) be used to solve the larger problem?
- What is/are the base case(s)?
REPORT THE NUMBER OF DIGITS IN AN INTEGER
Write a recursive function numdigs(k) that returns the number of (base 10) digits in its non-negative integer argument.
A run of a program that exercises this function might look like this:
Enter an integer: 12345 This integer contains 5 digits.
REVERSE A STRING
Write a recursive function reverse(s,n) that accepts an array s[.] whose initial segment contains n characters and prints out the characters in the segment in reverse order.
A run of a program that exercises this function might look like this:
Enter a string of characters: abcde98765$A The reversed string is: A$56789edcba
COMPUTING xn
Write a recursive function exp(x,n) that computes xn for a real value x and a non-negative integer n.
A run of the program that exercises this function might look like this:
Enter a real value: 14.3 Enter a non-negative integer exponent: 3 14.3 ^ 3 = 2924.207
HAND IN
For each of the three problems, hand in (1) a brief design document that describes the problem and the design of the function you have written to solve the problem; (2) the program's code; and (3) tests that demonstrate the function's effectiveness. For the entire project, hand in a summary. There is no need to include a user document in this project.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
