In a population, the birth rate and death rate are calculated as follows: Birth
ID: 3777287 • 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.
Explanation / Answer
The below code is in C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo
{
public class Program
{
static void Main(String[] args)
{ //Creating Population class object
Population population= new Population();
//Assigning values to Population class members
population.populationData=100000;
population.numberOfBirths=8000;
population.numberOfDeaths=6000;
double birthRate= population.GetBirthRate(population);
double deathRate = population.GetDeathRate(population);
if(birthRate!=-5)
{
Console.WriteLine(birthRate);
}
else { Console.WriteLine("Invalid Data"); }
if(deathRate!=5)
{
Console.WriteLine(deathRate);
}
else { Console.WriteLine("Invalid Data"); }
Console.ReadKey();
}
}
public class Population
{
//Defining properties, taking these as double so that they can handle decimal values
public double populationData { get; set; }
public double numberOfBirths { get; set; }
public double numberOfDeaths { get; set; }
//Defining Member functions
public double GetBirthRate(Population population)
{
if (population.populationData < 1 || population.numberOfBirths < 0)
{ return -5; }
else
{
return population.numberOfBirths / population.populationData;
}
}
public double GetDeathRate(Population population)
{
if (population.populationData < 1 || population.numberOfDeaths < 0)
{ return -5; }
else
{
return population.numberOfDeaths / population.populationData;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.