In a population, the birth rate and death rate are calculated as follows: Birth
ID: 3639450 • Letter: I
Question
In a population, the birth rate and death rate are calculated as follows:Birth Rate = Number of birth / population
Death Rate = Number of death / population
for example, in a population of 100,000 that has 8,000 births and 6,000 deaths per year, the birth 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 birth, and number of deaths for a period of time. Member function 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 number less then 0.
Explanation / Answer
class pop
(
public:
pop(int n, int b, int d)
{
if(n<1) exit 0;
else no = n;
if(b<0) exit 0;
else birth = b;
if(d<0) exit 0;
else death = d;
}
int brate()
{
return (float)birth/no;
}
int drate()
{
return (float)dedath/no;
}
private:
int birth, death, no;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.