If P is the population on the first day of the year, B is
the birth rate, and D is the death rate, the estimated
population at the end of the year is given by the formula:

The population growth rate is given by the formula:
B – D
Write a program that prompts the user to enter the starting
population, birth and death rates, and n, the number of
years. The program should then calculate and print the
estimated population after n years. Your program must have
at least the following functions:
1. growthRate: This function takes its parameters the
birth and death rates, and it returns the population growth
rate.
2. estimatedPopulation: This function takes its
parameters the current population, population growth rate,
and n, the number of years. It returns the estimated
population after n years
Your program should not accept a negative birth rate,
negative death rate, or a population less than 2.

Answer Posted / chaitanya raj budumuru

#include <iostream.h>
#include <conio.h>

class population
{
int b,d,p,n,c;
public:
void read()
{
c=1;
do
{
if(c>1)
{
cout<<"\n\nYou are entered wrong input";
cout<<"\nPress Enter And Re-Enter The Input";
getch();
c++;
}
clrscr();
cout<<"Enter The Birth and Death Rates:\n\t\t";
cin>>b>>d;
cout<<"\n\nEnter The current population:\n\t\t";
cin>>p;
cout<<"Enter How many Years Estimated:\n\t\t";
cin>>n;
}while(b<0&&d<0&&p<2);
}
int growth_rate(int b,int d)
{
return(b-d);
}
int estimatedPopulation(int p,
int growthrate(b,d),
int n)
{
for(int i=1;i<=n;++i) p=p+growthrate(b,d);
return p;
}
void execute()
{
read();
cout<<"The Population after"<<n<<"years"
<<estimatedPopulation(p,growthrate(b,d),n);
}
};

void main()
{
clrscr();
population pop;
pop.execute();
getch();
}

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is std :: string immutable?

559


Why is "using namespace std;" considered bad practice?

647


the first character in the variable name must be an a) special symbol b) number c) alphabet

603


What is class and structure in c++?

556


Explain how to initialize a const data member.

594






what is c++

1798


What is the default access level?

620


Assume an array of structure is in order by studentID field of the record, where student IDs go from 101 to 500. Write the most efficient pseudocode algorithm you can to find the record with a specific studentID if every single student ID from 101 to 500 is used and the array has 400 elements. Write the most efficient pseudocode algorithm you can to find a record with a studentID near the end of the IDs, say in the range from 450 to 500, if not every single student ID in the range of 101 to 500 is used and the array size is only 300

1783


Is c++ still being used?

561


You run a shell on unix system. How would you tell which shell are you running?

659


What is iostream in c++ used for?

549


Is overriding possible in c++?

570


Can a constructor be private?

577


What is pointer with example?

560


What is the protected keyword used for?

614