Problem B: (20 Points) Computing Population Growth based on the number of the ge
ID: 3887920 • Letter: P
Question
Problem B: (20 Points) Computing Population Growth based on the number of the generation, Revisited pulation-ecology-13228167, over twenty According t five percent of all amphibians are in serious danger of going extinct. Why are some species more vulnerable to extinction than others? How can current rates of individual survival and reproduction be projected into the future? The Earth's human population has doubled in less than fifty years. What challenges do we face with this unprecedented growth? What factors might most effect the rates of this growth into the future? Population ecology is the study of these and other questions about what factors affect population and how and why a population changes over time D For this problem you will write a program to calculate a population based on one of two very simple growth models. unspecified group of 1. Define and use a pure C++ function to calculate the future population of an ng organisms based on the number of generations of growth Equation a below can be used to the population of generaton N, based on the Inital populatdon of the organisms No, and o" where Q is the number of offspring per parent in one generation: Equation a) N-No The function should accept, ·and n as parameters and return, Define and use a pure C++ function to calculate the future population of an unspecified group of living organisms based on time and rate of doubling. Equation b below can be used to calculate the population of generation N, based on the initial population of the organisms No, and 2d where t is time and d is the rate of doubling, and both t and d are specified in the same units of measure 2. Equation b) N. N°2°/a . The function should accept No, t, and d as parameters and return N (Courtesy of Prof Joan Sonenewski Using appropriate UNIX commands and an editor, create and save a source file containing a Ct+ program the calculates the Population of for generation n (%) of an unspecified population, given user input of Ng, Q, and n, using the equation above, or calculates the population for at time t (N), given user input of No, t, and d. The next page ilustrates what example runs of your program should look like (user input is in bold font) after your program compiles without syntax, semantic, or run-time errors:Explanation / Answer
#include<iostream>
using namespace std;
// Function for method one. Assuming n is the number of generation of which we want to calculate the population.
unsigned long int mthd1(long int N0, int Q, int n)
{
unsigned long int N;
for(int i=0; i<n-1; i++)
Q*=Q;
N=N0*Q;
return(N);
}
//Function for method 2, assuming t/d results in an integer
unsigned long int mthd2(long int N0, int t, int d)
{
unsigned long int N;
int x=t/d;
long int p=1;
for(int i=0; i<x; i++)
p*=2;
N=N0*p;
return(N);
}
//Program to solve the given problem
int main()
{
long int N0;
int q,n,t,d;
cout<<"Do you want to enter 1. Number of off-springs per parent 2. Rate of doubling ?";
int ch;
cin>>ch;
switch(ch)
{
case 1:
{
cout<<" Enter the initial population ";
cin>>N0;
cout<<" Enter the number of offsprings per parent in one generation ";
cin>>q;
cout<<" For which generation is population counted? ";
cin>>n;
cout<<" The population of this generation is "<<mthd1(N0,q,n);
}
case 2:
{
cout<<" Enter the initial population ";
cin>>N0;
cout<<" Enter the rate of doubling ";
cin>>d;
cout<<" Enter the time ";
cin>>t;
cout<<" The population after "<< t<<"time is "<< mthd2(N0,t,d);
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.