Question

In C++ Transient Population Populations are effected by the birth and death rate, as well as...

In C++

Transient Population
Populations are effected by the birth and death rate, as well as the number of people who move in and out each year. The birth rate is the percentage increase of the population due to births and the death rate is the percentage decrease of the population due to deaths. Write a program that displays the size of a population for any number of years. The program should ask for the following data:

The starting size of a population P

The annual birth rate (as a percentage of the population expressed as a fraction in decimal form)B

The annual death rate (as a percentage of the population expressed as a fraction in decimal form)D

The average annual number of people who have arrived A

The average annual number of people who have moved away M

The number of years to display nYears

Write a function that calculates the size of the population after a year. To calculate the new population after one year, this function should use the formula
N = P + BP - DP + A - M
where N is the new population size, P is the previous population size, and B, D, A and M are as defined above. The function should return the value computed for N and should receive the values of P, B, D, A and M as parameters.

Prompts And Output Labels. The program first displays the message "This program calculates population change." on a line by itself, followed by these prompts for the inputs described above:      "Enter the starting population size: "
     "Enter the annual birth rate (as % of current population): "
     "Enter the annual death rate (as % of current population): "
     "How many individuals move into the area each year? ";
     "How many individuals leave the area each year? ";
     "For how many years do you wish to view population changes? "

The output of the program starts with a line:
Starting population: P (where P is the starting population (surprise)), and then continues with a separate line for each year, each line being of the form: Population at the end of year ||Y is P. (where Y is the year number (1,2,3,...) starting with 1, and where P is the population calculated for that year).

Input Validation. The program should validate all data read. None of the data should be negative, the number of years should not be less than 1 and the initial population should not be less than 2. If an invalid value is read, the program should print an error-specific message on a line by itself, followed by the directive "Please re-enter:" and then input another value-- until a valid value is entered. The error specific messages are: "Starting population must be 2 or more.", "Birth rate percent cannot be negative.", "Death rate percent cannot be negative.", "Arrivals cannot be negative.", "Departures cannot be negative.", and "Years must be one or more.".

1 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot of the code:

Sample Output:

Code to copy:

//Header files.

#include "stdafx.h"

#include <iostream>

#include <math.h>

using namespace std;

//Function declaration.

int newPopulation(int, double, double, int, int);

//main() function.

int main()

{

       //Declare variables.

       int p, m, leave, nyears, i;

       double b, d;

       //Print the output.

       cout << "This program calculates population change\n";

       //Prompt the user to enter starting popluation.

       cout << "Enter the starting population size: ";

       cin >> p;

       //Population must be two or more.

       while (p<2)

       {

              cout << "Starting population cannot be less than two.\n";

              //Prompt the user to enter the population again.

              cout << "Enter the starting population size: ";

              cin >> p;

       }

       //Prompt the user to enter the birth rate.

       cout << "Enter the annual birth rate"

              << " (as % of current population): ";

       cin >> b;

       //Birth rate cannot be negative.

       while (b<0)

       {

              cout << "Birth rate can never be negative.\n";

              //Prompt the user to enter the birth rate again.

              cout << "Enter the annual birth rate"

                     << " (as % of current population): ";

              cin >> b;

       }

       b /= 100.;

       //Prompt the user to enter the death rate.

       cout << "Enter the annual death rate"

              << " (as % of current population): ";

       cin >> d;

       //Death rate cannot be negative.

       while (d<0)

       {

              cout << "Death rate can never be negative.\n";

              //Prompt the user to enter the death rate again.

              cout << "Enter the annual death rate"

                     << " (as % of current population): ";

              cin >> d;

       }

       d /= 100.;

       //Prompt the user to enter the arrivals.

       cout << "How many individuals move into the area each year? ";

       cin >> m;

       //Arrivals cannot be negative.

       while (m<0)

       {

              cout << "Arrivals cannot be negative.\n";

              //Prompt the user to enter the arrivals again.

              cout << "How many individuals move into the area each year? ";

              cin >> m;

       }

       //Prompt the user to enter the number of people moved away.

       cout << "How many individuals leave the area each year? ";

       cin >> leave;

       //individuals leaving the area cannot be negative.

       while (leave<0)

       {

              cout << "Departures cannot be negative.\n";

              cout << "How many individuals leave the area each year? ";

              cin >> leave;

       }

       //Prompt the suer to enter the years.

       cout << "For how many years do you wish to"

              << "view population changes? ";

       cin >> nyears;

       //Minimum years shoud be 1.

       while (nyears<1)

       {

              cout << "The number of years should not be less than 1.\n";

              cout << "For how many years do you wish to view"

                     << "population changes? ";

              cin >> nyears;

       }

       cout << " Starting population: " << p<< endl;

       //Start the loop to print the results.

       for (i = 1;i <= nyears;i++)

       {

              p = newPopulation(p, b, d, m, leave);

              cout << "Population at the end of year "

                     << i << " is " << p << ".\n";

       }

       system("pause");

       return 0;

}

//newPopulation() function.

int newPopulation(int p, double b, double d, int a, int l)

{

       return (int)round(p + b*p - d*p + a - l);

}

Add a comment
Know the answer?
Add Answer to:
In C++ Transient Population Populations are effected by the birth and death rate, as well as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • P3.4 Population. In a population, the birth rate is the percentage increase of the population due...

    P3.4 Population. In a population, the birth rate is the percentage increase of the population due to births, and the death rate is the percentage decrease of the population due to deaths. Write a program that displays the size of a population for any number of years. The program should ask for the following data: The starting size of a population The annual birth rate The annual death rate The number of years to display Write a function that calculates...

  • Death rate > Birth or death rate (per capita) Birth rate - 1 Population Density ove...

    Death rate > Birth or death rate (per capita) Birth rate - 1 Population Density ove is a figure depicting density-dependent per capita birth and death rates of a single population. hich of the following statements is an ACCURATE conclusion about this population? This population will explode into an inñnite size as density increases. This population will decline to extinction if the population size is too small. This population is regulated by density-dependent negative feedback. This population exhibits exponential growth

  • In density independent populations, birth rate and death rate do not change with population density. In...

    In density independent populations, birth rate and death rate do not change with population density. In contrast for density dependent populations: A Birth rates decrease and death rates decrease Birth rates increase and death rates increase C. Birth rates decrease and death rates increase Birth rates increase and death rates decrease QUESTION 8 Why does the fitness of a phenotype depend on frequency-dependent selection? Because selection favors the least common phenotype. Because the least number of alleles are at that...

  • The initial population of A city is 40000. In a year, the birth and death rates...

    The initial population of A city is 40000. In a year, the birth and death rates of this city are 0.7 and 0.55, respectively. There is a series migration problem from city B to city A with 0.3 rate every 2 years. The maximum carrying capacity of this city is 90000. Model the population of growth for the city A in Simulink. a) What is the number of people after 8.5 years in City A? b) How many years later...

  • The birth rate of a population is b(r) - 2000.0221 people per year and the death...

    The birth rate of a population is b(r) - 2000.0221 people per year and the death rate is (t)- 14100,017 people per year, find the area between these curves for Osts 10. (Round your answer to the nearest Integer.) X people 5961

  • Populations grow when the number of births in a population is greater than the number of...

    Populations grow when the number of births in a population is greater than the number of deaths in the same population and there is no net movement of individuals into or out of the population. This is to say that all else being equal, populations grow when the birth rate exceeds the death rate and shrink when death rates exceed birth rates. When the number of births is equal to the number of deaths in a population, and again, there...

  • 1. Single Species Growth Consider a single population where the per capita birth rate declines as...

    1. Single Species Growth Consider a single population where the per capita birth rate declines as the population size grows. Let N(t) be the population size at time t. Consider the following assumptions: (A1) The environment in which the species lives (including the climate, other species and the availability of resources like food, etc.) remains constant. (A2) The per capita birth rate is for some b>0. (A3) The per capita death rate is a constant d > 0. Note: This...

  • Country A 144 Country B 82 43 8 18 10 Population (millions) Crude birth rate (number...

    Country A 144 Country B 82 43 8 18 10 Population (millions) Crude birth rate (number of live births per 1,000 people per year) Crude death rate (number of deaths per 1,000 people per year) Infant mortality rate (number of babies per 1,000 bom who die in first year of life) Total fertility rate (average number of children born to women during their childbearing years) % of population under 15 years old % of population older than 65 years Average...

  • Java

    Create a Java class (program) called PopulationGrowth.java. This program will compute the growth rates of a population over time. The program should take the following inputs from the user:p, the initial population size in the range [1...1000]b, the per capita birth rate in the range [0.0...1.0)d, the per capita death rate in the range [0.0...1.0)time_span, the number of years for which to compute population totalsOnce the input is finished, the program must compute the population for the next time_span years and display each...

  • Q2- Fish Population In this question, we will use differential equations to study the fish population...

    Q2- Fish Population In this question, we will use differential equations to study the fish population in a certain lake. An acceptable model for fish population change should take into account the birth rate, death rate, as well as harvesting rate Let P(t) denote the living fish population (measured in tonnes) at time t (measured in year) Then the net rate of change of the fish population in tonnes of fish per year is P'(t): P'(t) birth rate - death...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT