P5.4 Population. In a population, the birth rate is the percentage increase of t
ID: 3765573 • Letter: P
Question
P5.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 the size of the population for a year. The formula is
N = P + BP ? DP
where N is the new population size, P is the previous population size, B is the birth rate, and D is the death rate.
c++
C: Windows system32 cmd.exe his program calculates population change nter the starting population size: 10G0 nter the annual birth rate as % of current population): 3 nter the annual death rate as % of current population): 1.5 or how many years do you wish to view population changes? 20 tarting population: 1000 opulation at the end of year 1 is 1015. opulation at the end of year 2 is 1030. opulation at the end of year 3 is 1045 opulation at the end of year 4 is 1061. opulation at the end of year 5 is 1077?. opulation at the end of year 6 is 1093. opulation at the end of year 7 is 1109. opulation at the end of year 8 is 1126. opulation at the end of year 9 is 1143. opulation at the end of year 10 is 1160. opulation at the end of year 11 is 1177?. opulation at the end of year 12 is 1195. opulation at the end of year 13 is 1213. opulation at the end of year 14 is 1231 opulation at the end of year 15 is 1250. opulation at the end of year 16 is 1268. opulation at the end of year 17 is 1288. opulation at the end of year 18 is 1307. opulation at the end of year 19 is 1326. opulation at the end of year 20 is 1346 ress any key to continue -. .Explanation / Answer
#include<iostream.h>
#include<conio.h>
void population(int p, double b, double d, int n)
{
int i,bp,dp,N;
cout<<"Starting Population: "<<p;
for(i=1;i<=n;i++)
{
bp=p*b/100;
dp=p*d/100;
N=p+bp-dp;
cout<<"Population at the end of year "<<i <<"is "<<N<<endl;
}
}
void main()
{
int p,n;
double b,d;
while(true)
{
cout<<"Enter The starting size of a population";
cin>>p;
if(p>2)
break;
}
while(true)
{
cout<<"The annual birth rate";
cin>>b;
cout<<"The annual death rate";
cin>>d;
if(b>0 && d>0)
break;
}
while(true)
{
cout<<"The number of years to display";
cin>>n;
if(n>0)
break;
}
population(p,b,d,n);
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.