I have no idea how to construct this program. Any help is appreciated. Thank you.

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.

**Input Validation: Do not accept numbers less than 2 for the starting size. Do not accept negative numbers for birth or death rate. Do not accept numbers less than 1 for the number of years.

-------------------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
using namespace std;

double population(double pop, double birthRate, double deathRate);
void printPopulations(
double startPop, double birthRate, double deathRate, int numYears);

// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------

// --------------------------------
// --------- END USER CODE --------
// --------------------------------

int main()
{
double startPop, // To hold the starting population.
birthRate, // To hold the birth rate.
deathRate; // To hold the death rate.
int numYears; // To hold the number of years to track population changes.

// Input and validate starting population
cout << "This program calculates population change.\n";
cout << "Enter the starting population size: ";
cin >> startPop;
while (startPop < 2.0)
{
cout << "Starting population must be 2 or more. Please re-enter: ";
cin >> startPop;
}

// Input and validate annual birth and death rates
cout << "Enter the annual birth rate (as % of current population): ";
cin >> birthRate;
while (birthRate < 0)
{
cout << "Birth rate percent cannot be negative. Please re-enter: ";
cin >> birthRate;
}

birthRate = birthRate / 100; // Convert from % to decimal.

cout << "Enter the annual death rate (as % of current population): ";
cin >> deathRate;
while (deathRate < 0)
{
cout << "Death rate percent cannot be negative. Please re-enter: ";
cin >> deathRate;
}

deathRate = deathRate / 100; // Convert from % to decimal.

cout << "For how many years do you wish to view population changes? ";
cin >> numYears;
while (numYears < 1)
{
cout << "Years must be one or more. Please re-enter: ";
cin >> numYears;
}

printPopulations(startPop, birthRate, deathRate, numYears);
return 0;
} // End of main function.

Note that B and D are in percents, such as 2.5, so in the formula above

N=P+BP-DP
both B and D have to be divided by 100 to get the real fraction.

The header for population has already been defined, all you need to do is to fill in the required formula as given and return the result, as follows:

double population(double pop, double birthRate, double deathRate){
return pop*(1+(birthrate-deathRate)/100);
}

You can do that similarly for printPopulation. Post what you've got if you need help

To construct the program, you will need to complete the function population and the function printPopulations.

Here is an updated version of the code with the missing parts already filled in:

```cpp
#include <iostream>
#include <iomanip>
using namespace std;

double population(double pop, double birthRate, double deathRate) {
return pop + (pop * birthRate) - (pop * deathRate);
}

void printPopulations(double startPop, double birthRate, double deathRate, int numYears) {
double currentPop = startPop;
cout << "Population:\n";
cout << "Year \tSize\n";
cout << "--------------\n";
for (int i = 1; i <= numYears; i++) {
currentPop = population(currentPop, birthRate, deathRate);
cout << i << "\t" << fixed << setprecision(0) << currentPop << endl;
}
}

int main() {
double startPop, birthRate, deathRate;
int numYears;

cout << "This program calculates population change.\n";
cout << "Enter the starting population size: ";
cin >> startPop;
while (startPop < 2.0) {
cout << "Starting population must be 2 or more. Please re-enter: ";
cin >> startPop;
}

cout << "Enter the annual birth rate (as % of current population): ";
cin >> birthRate;
while (birthRate < 0) {
cout << "Birth rate percent cannot be negative. Please re-enter: ";
cin >> birthRate;
}

birthRate = birthRate / 100; // Convert from % to decimal.

cout << "Enter the annual death rate (as % of current population): ";
cin >> deathRate;
while (deathRate < 0) {
cout << "Death rate percent cannot be negative. Please re-enter: ";
cin >> deathRate;
}

deathRate = deathRate / 100; // Convert from % to decimal.

cout << "For how many years do you wish to view population changes? ";
cin >> numYears;
while (numYears < 1) {
cout << "Years must be one or more. Please re-enter: ";
cin >> numYears;
}

printPopulations(startPop, birthRate, deathRate, numYears);
return 0;
}
```

You can copy and run this code. It will prompt you to enter the starting population, birth rate, death rate, and number of years and then display the population size for each year.

To construct the program, you can follow these steps:

1. Start by including the necessary libraries `iostream` and `iomanip` at the beginning of the code:
```cpp
#include <iostream>
#include <iomanip>
using namespace std;
```

2. Define the function `population` that takes in the previous population size, birth rate, and death rate as input parameters. This function will calculate and return the new population size using the formula `N = P + BP - DP`.
```cpp
double population(double pop, double birthRate, double deathRate)
{
double newPop = pop + (pop * birthRate) - (pop * deathRate);
return newPop;
}
```

3. Define the function `printPopulations` that takes in the starting population, birth rate, death rate, and number of years to display as input parameters. This function will calculate and display the population for each year using a loop. Inside the loop, the function will use the `population` function to calculate the new population for each year.
```cpp
void printPopulations(double startPop, double birthRate, double deathRate, int numYears)
{
double currentPop = startPop;

cout << "Year" << setw(15) << "Population" << endl;
cout << "-------------------------------" << endl;

for (int year = 1; year <= numYears; year++)
{
cout << setw(4) << year << setw(12) << setprecision(0) << fixed << currentPop << endl;
currentPop = population(currentPop, birthRate, deathRate);
}
}
```

4. Implement the main function to handle user input and call the `printPopulations` function. Inside the main function, you need to validate the input values based on the given requirements.
```cpp
int main()
{
double startPop, birthRate, deathRate;
int numYears;

// Input and validate starting population
cout << "This program calculates population change.\n";
cout << "Enter the starting population size: ";
cin >> startPop;
while (startPop < 2.0)
{
cout << "Starting population must be 2 or more. Please re-enter: ";
cin >> startPop;
}

// Input and validate annual birth and death rates
cout << "Enter the annual birth rate (as % of current population): ";
cin >> birthRate;
while (birthRate < 0)
{
cout << "Birth rate percent cannot be negative. Please re-enter: ";
cin >> birthRate;
}
birthRate = birthRate / 100; // Convert from % to decimal.

cout << "Enter the annual death rate (as % of current population): ";
cin >> deathRate;
while (deathRate < 0)
{
cout << "Death rate percent cannot be negative. Please re-enter: ";
cin >> deathRate;
}
deathRate = deathRate / 100; // Convert from % to decimal.

cout << "For how many years do you wish to view population changes? ";
cin >> numYears;
while (numYears < 1)
{
cout << "Years must be one or more. Please re-enter: ";
cin >> numYears;
}

printPopulations(startPop, birthRate, deathRate, numYears);
return 0;
}
```

5. You can now compile and run the program to test its functionality. Make sure to provide valid input values that satisfy the input validation criteria.

Note: You need to add the provided code sections in appropriate places between the indicated comments to complete the program.