Write a function for each of the following problems within your main.cpp file an
ID: 3885579 • Letter: W
Question
Write a function for each of the following problems within your main.cpp file and make the appropriate calls to each function from within your main function. Problem1 The U.S. Census provides information about the current U.S. population as well as approximate rates of change. Using those rates and the current US population, write an algorithm to calculate the U.S population in exactly one year (365 days). Your algorithm should output the result of your calculations Three rates of change are provided a. There is a birth every 8 seconds b. There is a death every 12 seconds C. There is a new immigrant every 33 seconds Your function should take current population as an integer parameter Your function should return the population in a year Your function MUST be named howMany . For example, given an initial population of 1,000,000, your function would return 3,269,636
Explanation / Answer
C++:
#include <iostream>
using namespace std;
int howMany(int currPopulation) {
//total seconds in a year
int totalSeconds=365*24*60*60;
int births=totalSeconds/8;
int immigrants=totalSeconds/33;
int deaths=totalSeconds/12;
return ((births+immigrants)-deaths)+currPopulation;
}
int howLong(int seconds) {
int days=seconds/(24*60*60);
int hours=((seconds-(days*24*60*60))/(60*60));
int minutes=(seconds-((days*24*60*60)+(hours*60*60)))/60;
int secs=seconds-((days*24*60*60)+(hours*60*60)+(minutes*60));
cout<<"Time is "<<days<<" days, "<<hours<<" hours,"<<minutes<<" minutes, and "<<secs<<" seconds."<<endl;
}
int howHot(int celsius) {
int f=(celsius*1.8)+32;
return f;
}
int main(){
cout<<howMany(1000000)<<endl;
cout<<howLong(70000)<<endl;
cout<<howHot(20)<<endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.