Question
*******C++******** Problem: Your friend the biology lab assistant has a new job and now needs to monitor different populations of rabbits used in his lab.
*******C++********
Problem:
Your friend the biology lab assistant has a new job and now needs to monitor different populations of rabbits used in his lab. He needs to be able to predict the size of the population based on the initial population size and the average birth and death rates of the rabbits. Write a program that asks the user for an initial population size, the birth rate and death rate, and the number of years to monitor the population. Then calculate and output a table of changes in population size over those years.
The formula to compute the new population size is: N = P + B * P - D * P where N is the new population size, P is the previous population size, B is the birth rate, and D is the death rate. The birth and death rates are values between 0 and 1. Your program should output a table showing the starting population and the new population at the end of each year that the population is being monitored. To output the table, you will calculate the first year population using the initial population size for P, then calculate the second year using the first year population for P and so on, until you have calculated all of the requested years.
Finally, if the growth rate (the birth rate - death rate) is positive your program will notify the user in which year the population will double in size. The formula to calculate this is: n = log(2)/ log(1 + r) where log is a function in the cmath library, and r is the growth rate. If the growth rate is negative, you should notify the user in which year the population will become 0. The formula to calculate this is: n = log(1/P)/ log(1 + r) where P is the initial population size and r is the growth rate. If the growth rate is 0, you should notify the user that the population is stable.
Input: Ask the user for the initial population size, the birth rate, the death rate, and the number of years of population changes to report. The birth rate and death rate may have fractional values. You should validate the input as follows:
The initial population size should be at least 100 but not more than 1,000,000.
The birth rate and death rate should be greater than 0 and less than or equal to 100.
The years should be greater than 0. If the input is out of range, use an informative prompt to ask the user to re-enter valid data until the input is valid. For the calculations to work properly, you must convert the birth and death rates which are input as a percent (i.e. 3.5%) to fractional values between 0 and 1 (i.e. 0.035).
Processing: For full credit you must use the following 5 functions in your program.
getInput: has four reference parameters to input initial population size, birth rate, death rate, and number of years from the user.
calculatePop: has 3 parameters: population size, birth rate, and death rate. Returns the calculated new population size. Do not do any output from this function.
yearsToDouble: has 1 parameter, the growth rate (which should be positive). Returns the calculated number of years it takes for the population to double in size. Do not do any output from this function.
yearsToZero: has 2 parameter, the initial population and the growth rate (which should be negative). Returns the calculated number of years it takes for the population to reach 0. Do not do any output from this function.
outputTable: has 4 parameters: initial population size, birth rate, death rate, and total years. It outputs the table with column headers, and one row for each year from 0 to total years, showing the population size at the end of that year.
Output: Display the years and population size as whole numbers. Use the function floor in the cmath library to output the population sizes as whole numbers. The values in the table should line up (right-justified). You may assume that the population size will fit within 20 characters. Use the function ceil in the cmath library to output the number of years to double and years to reach 0 as whole numbers.
Sample output 1: Enter the initial population: 500 Enter the annual birth rate (as % of current population): 15 Enter the annual death rate (as % of current population): 10 Enter the number of years of population changes: 20 Year Population 500 525 551 578 607 638 670 703 738 775 814 855 897 942 989 1039 1091 1146 1203 1263 1326 2 3 4 10 12 13 14 15 16 17 18 19 20 Population will double in 15 yearsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started