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.



If P is the population on the first day of the year, B is the birth rate, and D is the death rate,..

Answer / 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

More C++ General Interview Questions

How would you use the functions sin(), pow(), sqrt()?

0 Answers  


How to declare an array of pointers to integer?

0 Answers  


Which of the following is evaluated first: a) && b) || c) !

0 Answers  


Const char *p , char const *p What is the difference between the above two?

0 Answers   TCS,


How do you invoke a base member function from a derived class in which you’ve overridden that function?

0 Answers  






What is an incomplete type?

1 Answers  


Explain calling an object's member function(declared virtual)from its constructor?

1 Answers  


What are the advantages of C++ programming compared to C programming?

2 Answers   HAL,


what is polymorphism?

14 Answers   Accenture,


What are the differences between new and malloc?

0 Answers  


What are the differences between public, private, and protected access?

12 Answers   IBM, Oracle, Wipro,


write a program that reads in a file and counts the number of lines, words, and characters. Your program should ask the user to input a filename. Open the file and report an error if the file does not exist or cannot be opened for some other reason. Then read in the contents of the file and count the number of lines, words, and characters in the file. Also print additional information about the file, such as the longest and shortest words, and longest and shortest lines. For simplicity, we define a word to be one or more characters ending with white space (a space, tab, carriage return, etc.). Functions for checking the types of characters can be found in the ctype.h header file, so you want to include this header file in your program. For example, the sentence below could be all that is in a file. This sentence IT 104 is taught in C++. has 32 characters, one line, and six words. The shortest line is 32 characters. The longest line is 32 characters. The shortest word is 2 characters. The longest word is 6 characters

0 Answers  


Categories