subject

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
• 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.
Input Validation: Do not accept numbers less than 2 for the starting size. Do not accept negative numbers for birth rate or death rate. Do not accept numbers less than 1 for the number of years.
#include
using namespace std;
double calcOfPopulation(double, double, double);
double inputValidate(double, int);
int main()
{
double P, // population size
B, // birth rate %
D, // death rate %
num_years;
cout << "Starting size of population: ";
P = inputValidate(P, 2);
cout << "Annual birth rate: %";
B = inputValidate(B, 0);
cout << "Annual death rate: %";
D = inputValidate(D, 0);
cout << "Number of years to display: ";
num_years = inputValidate(num_years, 1);
cout << "Population size for "
<< num_years << " years "
<< " = "
<< (calcOfPopulation(P, B, D) * num_years)
<< endl;
return 0;
} // END int main()
double inputValidate(double number, int limit)
{
while(!(cin >> number) || number < limit)
{
cout << "Error. Number must not be "
<< " 0 or greater:";
cin. clear();
cin. ignore(numeric_limits::max(), '\n');
}
return number;
}
double calcOfPopulation(double P, double B, double D)
{
B *= .01; // 3.33% = .0333
D *= .01; // 4.44% = .0444
return P + (B * P) - (D * P);

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 16:20, mandy9386
Consider the following statements, then select one of the answers below: the signal() function shown below registers "sig_handler()" as the signal handler function for the sigkill signal, without the complexity of using when the sigkill signal is sent to a process running this code, by a user typing "kill -kill ", where the correct process id is used for to target the process, sig_handler() will be executed.
Answers: 1
image
Computers and Technology, 23.06.2019 07:30, kimhoss2
What are ways to switch windows in excel? check all that apply. on the status bar, click the windows button, and then click the file name. on the task bar, click to display the excel jump list, and then click the file name. on the view tab, in the window group, click switch windows, and then click the file name. on the review tab, in the viewing group, click files, and then click the file name.
Answers: 1
image
Computers and Technology, 23.06.2019 07:50, madim1275
Most shops require the technician to enter a starting and ending time on the repair order to track the actual time the vehicle was in the shop and closed out by the office. this time is referred to as _ time ? a. comeback b. ro c. cycle d. lead
Answers: 1
image
Computers and Technology, 23.06.2019 14:00, LuvIsRage2
Technician a says that with self-adjusting clutch systems, the release bearing constantly rotates. technician b says that the ball bearing portion of the release bearing should be lubricated with high-temperature grease during routine maintenance. which technician is correct?
Answers: 2
You know the right answer?
Populations are effected by the birth and death rate, as well as the number of people who move in an...

Questions in other subjects: