#include<iostream> using namespace std; //Birth rate = number ofbirths / populat
ID: 3610462 • Letter: #
Question
#include<iostream>
using namespace std;
//Birth rate = number ofbirths / population
//death rate = number of deaths / population
class Population
{
private :
double population,births,deaths;
public:
double setPopulation(double p)
{
if(p<2)
population = 2;
else
population = p;
return (p);
}
double setBirths(double b)
{
if(b < 0)
births = 0;
else
births = b;
return (b);
}
doublesetDeaths(double d)
{
if(d <0)
deaths = 0;
else
deaths = d;
return (d);
}
double getBirthRate()
{
return (births/population);
}
double getDeathRate()
{
return (deaths/population);
}
};
int main()
{
Population pop;
double population, births, deaths;
cout << "Whatis the population? " << endl;
cin >> population;
pop.setPopulation(population);
cout << "Howmany births are there? " << endl;
cin >> births;
pop.setBirths(births);
cout << "Howmany deaths are there? " << endl;
cin >> deaths;
pop.setDeaths(deaths);
cout << "Thebirth rate is: " << pop.getBirthRate() << endl;
cout << "The death rate is: " <<pop.getDeathRate() << endl;
return 0;
}
Explanation / Answer
please rate - thanks why should they be 0 births=1, deaths=1, population=1 births/population=1/2=.5 which is what yougot deaths/population=1/2=.5 which is what you got if the variables were all int and not double then 1/2=0 double getBirthRate() { return (births/population); } double getDeathRate() { return (deaths/population); }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.