This program is about an imaginary animal called a jackalope. Each generation, t
ID: 3640557 • Letter: T
Question
This program is about an imaginary animal called a jackalope. Each generation, the jackalope population increases by 3% due to births and decreases by 1% due to deaths. Both the number of jackalopes who die and who are born will be rounded down (truncated) to an integer. So using a simple formula for calculating the number of jackalopes after a generation:If you start with 200 jackalopes, then 3% more are born, increasing the number to 206. 1% of the 206 die, decreasing the number to 204.
If you were to start with 132 jackalopes, then 3 would be born (132 * 0.03 = 3.96, rounded down to 3) and of the 135, 1 would die (135 * 0.01 = 1.35, rounded down to 1), leaving us with 134 jackalopes. The following generation, 3% of the 134 would produce 4 births, and 1% of 138 would produce 1 death, leaving us with 137. Note that this isn't the same result as if we simply add 2% each year.
You should define named constants (using const) for birth and death rates to use in your calculations.
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
const int BIRTHRATE=3;
const int DEATHRATE=1;
int nb,nd,c=1,ng,jn;
cout<<"Enter the number of jackalopes: ";
cin>>jn;
cout<<"Enter the number of generations for which to be found: ";
cin>>ng;
while(ng!=0)
{
nb=jn*BIRTHRATE/100;
nd=jn*DEATHRATE/100;
jn=jn+nb-nd;
cout<<" For generation "<<c;
cout<<" ======================";
cout<<" Number of births: "<<nb;
cout<<" Number of deaths: "<<nd;
cout<<" Total number of population: "<<jn;
c++;
ng--;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.