fork download
  1. //Andrew Alspaugh CS1A Chapter 6. P. 373. #15
  2.  
  3. /****************************************************************************
  4.  * Calculate Population Increase/Decrease
  5.  * __________________________________________________________________________
  6.  * This Program takes a starting population, a birth and death rate, and a
  7.  * time period to estimate the size of a population
  8.  * _________________________________________________________________________
  9.  * INPUT:
  10.  * population - starting population
  11.  * birthRate - rate of increase
  12.  * deathRate - rate of decrease
  13.  * period - time period of increase/decrease
  14.  *
  15.  * OUTPUT:
  16.  * NewPop - new population after calculation
  17.  * ***************************************************************************/
  18.  
  19. #include <iostream>
  20. using namespace std;
  21.  
  22. //prototype
  23. long CalculateNewPop(long population, double birthRate, double deathRate, int period);
  24.  
  25. int main()
  26. {
  27. //DATA DICTIONARY
  28. long population;
  29. double birthRate;
  30. double deathRate;
  31. int period;
  32.  
  33. long NewPop;
  34. //INPUT
  35. //population
  36. cout << "Enter Population at beginning of time period:" << endl;
  37. cin >> population;
  38. while (population <= 2)
  39. {
  40. cout << "Invalid Input: Population must be greater than 2" << endl;
  41. cin >> population;
  42. }
  43. cout << "Starting Population is " << population << endl;
  44.  
  45. //birthRate
  46. cout << "Enter Annual Birth Rate As A Percent:" << endl;
  47. cin >> birthRate;
  48. while(birthRate < 0)
  49. {
  50. cout << "Invalid Input: Rate cannot be negative" << endl;
  51. cin >> birthRate;
  52. }
  53. cout << "Birth Rate is " << birthRate << " percent annual increase" << endl;
  54.  
  55. //deathRate
  56. cout << "Enter Annual Death Rate As A Percent:" << endl;
  57. cin >> deathRate;
  58. while(deathRate < 0)
  59. {
  60. cout << "Invalid Input: Rate cannot be negative" << endl;
  61. cin >> deathRate;
  62. }
  63. cout << "Death Rate is " << deathRate << " percent annual decrease" << endl;
  64.  
  65. //period
  66. cout << "Enter Time Period for Population" << endl;
  67. cin >> period;
  68. while (period <= 0)
  69. {
  70. cout << "Invalid Input: Number of years cannot be less than 1" << endl;
  71. cin >> period;
  72. }
  73. cout << "The time period for population change calculated will be " << period << endl;
  74.  
  75. //PROCESS
  76. NewPop = CalculateNewPop(population, birthRate, deathRate, period);
  77.  
  78. //OUTPUT
  79. cout << "The New Population will be " << NewPop << endl;
  80. return 0;
  81. }
  82.  
  83. //CalculateNewPop() Definition
  84. long CalculateNewPop(long population, double birthRate, double deathRate, int period)
  85. {
  86. long NewPop = 0;
  87. NewPop=population+(population*(birthRate/100 + 1))-(population*(deathRate/100 + 1));
  88. return NewPop;
  89. }
  90.  
  91.  
  92.  
Success #stdin #stdout 0.01s 5320KB
stdin
92309402
167
69
250
stdout
Enter Population at beginning of time period:
Starting Population is 92309402
Enter Annual Birth Rate As A Percent:
Birth Rate is 167 percent annual increase
Enter Annual Death Rate As A Percent:
Death Rate is 69 percent annual decrease
Enter Time Period for Population
The time period for population change calculated will be 250
The New Population will be 182772615