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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 15:00
Hyperactive media sales has 10 windows 7 laptop computers used by sales-people in the organization. each laptop computer has several customized applications that are used during the sales process as well as customer relationship management software. all of the applications on the laptops are difficult to configure and have large data files. if all of the laptops have current hardware, what is the easiest way to install windows 10 on them?
Answers: 1
question
Computers and Technology, 22.06.2019 20:40
Assume that there is a 4% rate of disk drive failure in a year. a. if all your computer data is stored on a hard disk drive with a copy stored on a second hard disk drive, what is the probability that during a year, you can avoid catastrophe with at least one working drive? b. if copies of all your computer data are stored on three independent hard disk drives, what is the probability that during a year, you can avoid catastrophe with at least one working drive?
Answers: 1
question
Computers and Technology, 23.06.2019 02:30
How to launch an app: steps to be successful? launching an app is a great idea, but it’s not that easy as we supposed to think. the majority of mobile applications don’t generate revenue because companies aren’t ready to be competitive. referring to our experience in successfully building and launching apps we hope to you omit these difficulties. we are going to talk about ideas, marketing, testing your product, its development, distribution and support. you will learn 8 product launch stages to succeed.
Answers: 1
question
Computers and Technology, 23.06.2019 16:30
You have read about the beginnings of the internet and how it was created. what was the internet originally created to do? (select all that apply) share research. play games. communicate. share documents. sell toys
Answers: 1
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
question
Biology, 21.02.2021 09:00
question
Mathematics, 21.02.2021 09:00
question
Mathematics, 21.02.2021 09:00
question
Mathematics, 21.02.2021 09:00
Questions on the website: 13722361