Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Problem Problem: Your friend the biology lab assistant has a new job and now needs to monitor different populations of rabbits used in his

C++ Problem

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) 1 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
---- -----------------
0 500
1 525
2 551
3 578
4 607
5 638
6 670
7 703
8 738
9 775
10 814
11 855
12 897
13 942
14 989
15 1039
16 1091
17 1146
18 1203
19 1263
20 1326

Population will double in 15 years.

Sample output 2: Enter the initial population: 100 Enter the annual birth rate (as % of current population): 1 Enter the annual death rate (as % of current population): 45 Enter the number of years of population changes: 10

Year Population
---- ------------
0 100
1 56
2 31
3 17
4 9
5 5
6 3
7 1
8 0
9 0
10 0

Population will be zero in 8 years.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions