//Andrew Alspaugh CS1A Chapter 6. P. 373. #15
/****************************************************************************
* Calculate Population Increase/Decrease
* __________________________________________________________________________
* This Program takes a starting population, a birth and death rate, and a
* time period to estimate the size of a population
* _________________________________________________________________________
* INPUT:
* population - starting population
* birthRate - rate of increase
* deathRate - rate of decrease
* period - time period of increase/decrease
*
* OUTPUT:
* NewPop - new population after calculation
* ***************************************************************************/
#include <iostream>
using namespace std;
//prototype
long CalculateNewPop(long population, double birthRate, double deathRate, int period);
int main()
{
//DATA DICTIONARY
long population;
double birthRate;
double deathRate;
int period;
long NewPop;
//INPUT
//population
cout << "Enter Population at beginning of time period:" << endl;
cin >> population;
while (population <= 2)
{
cout << "Invalid Input: Population must be greater than 2" << endl;
cin >> population;
}
cout << "Starting Population is " << population << endl;
//birthRate
cout << "Enter Annual Birth Rate As A Percent:" << endl;
cin >> birthRate;
while(birthRate < 0)
{
cout << "Invalid Input: Rate cannot be negative" << endl;
cin >> birthRate;
}
cout << "Birth Rate is " << birthRate << " percent annual increase" << endl;
//deathRate
cout << "Enter Annual Death Rate As A Percent:" << endl;
cin >> deathRate;
while(deathRate < 0)
{
cout << "Invalid Input: Rate cannot be negative" << endl;
cin >> deathRate;
}
cout << "Death Rate is " << deathRate << " percent annual decrease" << endl;
//period
cout << "Enter Time Period for Population" << endl;
cin >> period;
while (period <= 0)
{
cout << "Invalid Input: Number of years cannot be less than 1" << endl;
cin >> period;
}
cout << "The time period for population change calculated will be " << period << endl;
//PROCESS
NewPop = CalculateNewPop(population, birthRate, deathRate, period);
//OUTPUT
cout << "The New Population will be " << NewPop << endl;
return 0;
}
//CalculateNewPop() Definition
long CalculateNewPop(long population, double birthRate, double deathRate, int period)
{
long NewPop = 0;
NewPop=population+(population*(birthRate/100 + 1))-(population*(deathRate/100 + 1));
return NewPop;
}