In 2022 population of town A is less than population of town B. However, the population of town A is growing faster than the population in town B. Write a program that calculates and displays a year when population of town A becomes equal to larger than that of town B. Program specifications: a. Write function void signature() that shows your name, student ID and current date on the top of the output. b. Write a function long getPopulation(long pop, double rate) which takes a current population and the rate of population growth as a decimal value, and calculates population growth in a year, using pop += pop*decRate; c. Assign initial population numbers for each town (in 2022) as follows: initial population of town A is your STUDNET ID (digits only); initial population of town B is larger by 100,000. Declare these initial values as constants. NOTE: all variables and constants for population should be declared as long, or long int data type d. Obtains floating-point rates of population growth for each town as random floating-point number in the range 2% to 4%. (Hint: generate a random integer in the range 20 to 40, convert to float (or double) and divide by 10.) Do this inside a while loop to ensure that final rateA is larger than rateB ( but these will be still percentages, like 2.6%, etc.) e. The program then uses a loop to calculates population of each town for the next 50 years, compares the values for each year, and display them in a table (see example of the output). The calculations should stop when population of A exceeds (or equal to) that of B; f. Then it displays a message showing the year when the population of town A will be greater than or equal to the population of town
In 2022 population of town A is less than population of town B. However, the population
of town A is growing faster than the population in town B. Write a program that
calculates and displays a year when population of town A becomes equal to larger than
that of town B.
Program specifications:
a. Write function void signature() that shows your name, student ID and
current date on the top of the output.
b. Write a function
long getPopulation(long pop, double rate)
which takes a current population and the rate of population growth as a
decimal value, and calculates population growth in a year, using
pop += pop*decRate;
c. Assign initial population numbers for each town (in 2022) as follows: initial
population of town A is your STUDNET ID (digits only); initial population of
town B is larger by 100,000. Declare these initial values as constants. NOTE:
all variables and constants for population should be declared as long, or long
int data type
d. Obtains floating-point rates of population growth for each town as random
floating-point number in the range 2% to 4%. (Hint: generate a random
integer in the range 20 to 40, convert to float (or double) and divide by 10.)
Do this inside a while loop to ensure that final rateA is larger than rateB
( but these will be still percentages, like 2.6%, etc.)
e. The program then uses a loop to calculates population of each town for the
next 50 years, compares the values for each year, and display them in a table
(see example of the output). The calculations should stop when population of
A exceeds (or equal to) that of B;
f. Then it displays a message showing the year when the population of town A
will be greater than or equal to the population of town B.
Step by step
Solved in 3 steps with 1 images