using C language Write a program that approximates the popul
using C++ language
Write a program that approximates the population growth of a species assuming the exponential growth model P_t = (1 + r - E)P_t-1, where P_t represents this year\'s population, P_t-1 represents last year\'s population, r = (birth rate - death rate) is the growth rate constant, and E is an additional effect on the species due to environmental causes that has some inherent randomness and changes from year to year. This additional effect can be interpreted as adding or subtracting individuals from a population. When E = 0, we say the model is deterministic and P(t) = P_0(1 + r)^t, where P_0 represents the initial population and P(t) is the number of individuals in the population after t years. Note that for the determinist growth model in equation (3), we can compute the population at any year t = T by simply knowing Po and r. For the model that includes environmental influences in equation (1), we need to compute all the years from t = 0 to t = (T - 1) before we can compute P_T. Start your program by prompting the user to enter the initial population P_0, the birth rate, the death rate, and the amount of years T you are interested in studying the given population. Then, assuming the same trend will continue, write a function growth rate that returns the growth rate constant r and a function population that estimates the population, choosing the right model depending on the value of E. Using the deterministic model in equation (3), make your program find the estimate population P(T) after T years. Implement the function extinction to determine if extinction is possible under given conditions. Using the environmental model from equation (1), call the population function to output one estimate of Pp by computing the random environmental rate E for each year. Implement another function extinction probability to compute the probability that the species will become extinct during T years under the random environmental model. You can do this by computing the population Pt under the environmental model 100 times and counting how many times the population becomes extinct. Your program should not allow an initial population less than 2, negative population, or fractional population. Keep the random effect restricted such that -1Solution
#include <iostream>
 #include <cstdlib>
 #include <ctime>
 #include <cmath>
 using namespace std;
double growth_rate( double bRate, double dRate ){
    return bRate - dRate;
 }
int population( int iPopulation, int years, double rate, int model_no ){
    if( model_no == 1 ){ return iPopulation*pow( 1.0 + rate, years ); }
    double newPopulation = iPopulation;
    for(int yr = 1; yr <= years; yr++ ){
        if(newPopulation <= 0 ){ newPopulation = 0; break; }
        double E = -1 + ( (double)rand()/RAND_MAX )*(2);
        newPopulation = ( 1 + rate - E )*newPopulation;
    }
    return newPopulation;
 }
bool extinction( double rate ){
    if( rate < 0 ){ return true; }
    return false;
 }
double extinction_probability( int iPopulation, int years, double rate ){
    int extinct = 0;
    for(int i = 0; i < 100; i++){
        int newP = population( iPopulation, years, rate, 2 );
        if( newP == 0 ){ extinct++; }
    }
    return extinct*0.01;
 }
int main(){
    srand(time(NULL));
   
    double iPop;
    int iPopulation, years;
    double bRate, dRate;
   cout << \"Initial Population = \";
    cin >> iPop;
    cout << \"Birth Rate = \";
    cin >> bRate;
    cout << \"Death Rate = \";
    cin >> dRate;
    cout << \"Years = \";
    cin >> years;
    cout << endl << endl;
   if( iPop < 2 || ((int)(iPop) != iPop ) ){
        cout << \"Invalid initial population\" << endl;
        return 0;
    }
    iPopulation = iPop;
    double rate = bRate - dRate;
   cout << \"MODEL\\t\\t\\tYEARS\\t POPULATION\\tEXTINCTION\" << endl;
    cout << \"DETERMINISTIC\\t\\t\" << years << \"\\t\\t\";
    cout << population( iPopulation, years, rate, 1 ) << \"\\t\";
    if( extinction(rate) ){
        cout << \"POSSIBLE\" << endl;
    }
    cout << \"ENVIRONMENTAL\\t\\t\" << years << \"\\t\\t\";
    cout << population( iPopulation, years, rate, 2 ) << \"\\t\";
    cout << \"PROB = \" << extinction_probability( iPopulation, years, rate ) << endl;
    return 0;
 }


