Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Lab - Recursive Algorithms For this lab you will implement 4 different recursive algorithms. You are supplied with the starter file recursionlab.cpp which includes

C++ image text in transcribed
image text in transcribed
image text in transcribed
Lab - Recursive Algorithms For this lab you will implement 4 different recursive algorithms. You are supplied with the starter file recursionlab.cpp which includes main() for testing. Add your solutions to the problems below to recursionlab.cpp. All solutions should be recursive. Do not alter the provided main(). Problem 1 - Recursive Exponentiation Write a recursive function power (base, exponent) that, when invoked, returns baseponent For example, 3* would be calculated by the call power (3, 4) which would return 81. You may assume base >0 and exponent 20. Problem 2 - Sum the Sequence Write a recursive function sum (num) which returns the sum of the integers from 0 through integer num. You may assume num > 0. For example, sum (4) calculates 0+1+2+3+4 and returns 10. sum (0) returns 0. Problem 3 - Display a Sequence A sequence is a series of values. Write a recursive function display Sequence. (start, difference, numofTerms) that displays a sequence of integers separated by spaces where: start is the int that begins the sequence. This can be any integer. difference is the integer that determines the difference between each number in the sequence. This number is added to the previous term in the sequence to determine the next term. This can be any integer. numofterms is the number of terms to display in the sequence. This should be zero or larger. For example, axsestuense (1, 2, 5) should display a sequence that begins with 1. calculates each new term by adding 2 to the previous term, and displays 5 terms in total. So, it displays: 1 3 5 7 9 Problem 4 - Sum the Digits Write a recursive function sumThe Digits (num) which returns the sum of the digits in integer num. You may assumen 20. For example, sumTheRigits (5129) calculates 5+1+2+ 9 and returns 17. For any n less than 10 the original number is returned. For instance, sumTheDigits.(5) returns 5. Hint: While I'm sure there are different solutions, consider pulling off the smallest digit first. For instance, given the integer 5129, first pull off 9 leaving you with 5120. Then convert 5120 to 512. Turn In Upload your completed recursionLab.cpp prior to the due date. #include using namespace std; int main() { cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+5. What does this public think about your organization?

Answered: 1 week ago