#include <iostream>
#include <iomanip>
using namespace std;
class Population
{
private:
int pop;
int births;
int deaths;
public:
void setPopulation (int);
void setBirths(int);
void setDeaths(int);
int getPopulation();
double getBirthRate();
double getDeathRate();
Population() : pop(0), deaths(0), births(0) {}
};
void Population::setPopulation(int p)
{
pop = p;
}
void Population::setBirths(int B)
{
births = B;
}
void Population::setDeaths(int d)
{
deaths = d;
}
int Population::getPopulation()
{
return pop;
}
double Population::getBirthRate()
{
return births / static_cast<double>(pop);
}
double Population::getDeathRate()
{
return deaths / static_cast<double>(pop);
}
int main()
{
Population Town;
int People;
int Births,
Deaths;
cout << "Enter total population: ";
cin >> People;
while (People < 1)
{ cout << "ERROR: Value has to be greater than 0. ";
cin >> People;
}
Town.setPopulation(People);
cout << "Enter annual number of births: ";
cin >> Births;
while (Births < 0)
{ cout << "ERROR: Value cannot be negative. ";
cin >> Births;
}
Town.setBirths(Births);
cout << "Enter annual number of deaths: ";
cin >> Deaths;
while (Deaths < 0)
{ cout << "ERROR: Value cannot be negative. ";
cin >> Deaths;
}
Town.setDeaths(Deaths);
cout << "\nPopulation Statistics ";
cout << fixed << showpoint << setprecision(3);
cout << "\n\tPopulation: " << setw(7) << Town.getPopulation();
cout << "\n\tBirth Rate: " << setw(7) << Town.getBirthRate();
cout << "\n\tDeath Rate: " << setw(7) << Town.getDeathRate() << endl;
return 0;
}