-
Notifications
You must be signed in to change notification settings - Fork 0
/
01.11.population projection.cpp
59 lines (45 loc) · 1.78 KB
/
01.11.population projection.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
using namespace std;
/*
=======================================
1.11. Population Projection
by : Putra
---------------------------------------
Problem:
The U.S. Census Bureau projects population
based on the following assumptions:
=> One birth every 7 seconds
=> One death every 13 seconds
=> One new immigrant every 45 seconds
Write a program that displays the
population for each of the next five years.
Assume the current population is
312,032,486 and one year has 365 days.
Hint: In C++, if two integers perform
division, the result is the quotient.
The fractional part is truncated.
For example, 5 / 4 is 1 (not 1.25) and
10 / 4 is 2 (not 2.5). To get an accurate
result with the fractional part, one of
the values involved in the division must
be a number with a decimal point. For
example, 5.0 / 4 is 1.25 and 10 / 4.0
is 2.5.
=======================================
*/
int main() {
// 1. Define variables.
int numberOfBirths;
int numberOfDeaths;
int numberOfNewImigrants;
// 2. Calculate each variable.
numberOfBirths = (5 * 365 * 24 * 3600) / 7;
numberOfDeaths = (5 * 365 * 24 * 3600) / 13;
numberOfNewImigrants = (5 * 365 * 24 * 3600) / 45;
// 3. Calculate the results of population projections in 5 year later.
int populationProjection;
populationProjection = 312032486 + numberOfBirths + numberOfNewImigrants - numberOfDeaths;
// 4. Display the results of population projections in 5 year later.
cout << "The results of population projections in 5 year later is " << populationProjection << "." << endl;
return 0;
}