In a population, the birth rate and death rate are calculated as follows: Birth
ID: 3779879 • Letter: I
Question
In a population, the birth rate and death rate are calculated as follows:
Birth Rate = Number of Births ÷ Population
Death Rate = Number of Deaths ÷ Population
For example, in a population of 100,000 that has 8,000 births and 6,000 deaths per year, the birth rate and death rate are:
Birth Rate = 8,000 ÷ 100,000 = 0.08
Death Rate = 6,000 ÷ 100,000 = 0.06
Design a Population class that stores a population, number of births, and number of deaths for a period of time. Member functions should return the birth rate and death rate. Implement the class in a program. Input Validation: Do not accept population figures less than 1, or birth or death numbers less than 0. (C++)
Explanation / Answer
#include<iostream>
using namespace std;
class Population
{
long population;
long no_births;
long no_deaths;
public:
//constructor to initialize private members to zero
Population()
{
population = 0;
no_births = 0;
no_deaths = 0;
}
//method to set values of an object of type Population
void set_population(long pol, long births, long deaths)
{
population = pol;
no_births = births;
no_deaths = deaths;
}
//method to calculate birth rate
double birth_rate()
{
double rate =((double)no_births/population)*100;
return rate;
}
//method to calculate death rate
double death_rate()
{
double rate = ((double)no_deaths/population)*100;
return rate;
}
};
int main()
{
//declare an object of type population
Population obj;
//local variable to store values entered from user
long polulation,births,deaths;
cout<"Enter values for population, number of births , number of deaths ";
cout<<"Population = ";
cin>>polulation;
cout<<"births = ";
cin>>births;
cout<<"deaths = ";
cin>>deaths;
//set above values for an object pol
obj.set_population(polulation,births,deaths);
cout<<"Birth rate = "<<obj.birth_rate()<<"%"<<endl;
cout<<"Death rate = "<<obj.death_rate()<<"%"<<endl;
}
------------------------------------------------------------------------
output
Population = 200000
births = 12344
deaths = 8970
Birth rate = 6.172%
Death rate = 4.485%
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.