Question: This week we are digging deeper into recursive algorithms. Because most natural processes that we want to study are based on recursive behaviors (the number

This week we are digging deeper into recursive algorithms. Because most natural processes that we want to study are based on recursive behaviors (the number of new plants in a season is directly correlated to how many there are this season), the art of modeling these systems often lends itself to computer algorithms using recursion. The assignment this week is to develop a recursive algorithm to determine how many generations it will take before a population reaches a certain size. I have provided you with a function uint updatePopulation(uint n) that takes a population number and returns the next step in that population growth. The algorithm I'm using for this problem is very straight forward current population - average deaths + average births. In reality the update population function would grow to become much more complicated, could have any number of contributing factors involving population size, existing land etc, etc BUT notice the underlying algorithm for calculating population over multiple generations would remain the same if written correctly to depend on the updatePopulation function. You assignment is to fill in the function howManyGenerations(uint start, uint final) that RECURSIVELY determines how many generations it will take to reach the final value given the start value.

IMPORTANT NOTE: For this assignment it is not enough to pass the test. I will be checking your algorithms to see that you have a recursive function (one that calls itself repeatedly to get to a base case). If you do not have a recursive algorithm, you will not receive credit for this lab. Also, in your howManyGenerations functions you need to use the updatePopulation function to determine the population growth, if you do not call the updatePopulation function to determine the next generation size you will not receive credit for this assignment. The assignment is worth 25 points.

#include #include #include

using namespace std;

typedef unsigned int uint;

uint updatePopulation(uint currentPopulation) { uint numBirths = .0185*(currentPopulation); uint numDeaths = .0008*(currentPopulation); return currentPopulation + numBirths - numDeaths; }

uint howManyGenerations(uint startAmount, uint finalAmount) { /// /// insert your code here /// return 0; //update this return value as appropriate }

int main() {

uint finalAmount = 1000000; uint startAmount = 100; if (howManyGenerations(startAmount, finalAmount) == 537) { cout<<"PASSED start=100, final=1000000"<

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!