You have made it as a software engineer, living and working as a remote traveling blogger as a side hustle. As you can’t always rely on being near a coffee shop, you travel with an electric kettle that can be set to a specific temperature. As you travel around, sometimes you travel to high elevations and the boiling point of water will change due to pressure, so you must change the boiling point temperature setting on your machine. (If you leave it at the default setting, 100 degrees C, it boils way too fast and scalding hot water can spew out of the kettle’s ventilation holes and burn hands.)
As you don’t always have internet access to look this up, you must make a simple program that looks up the city you are in, and given the elevation, calculates pressure and boiling point.
Example input files are already created for you – a list cities you plan on visiting, and their respective states and elevations. You should list the input file on the command line to be received by your program with argv/argc.
The command line usage is
1
./boiling my-input-file.csv
with boiling as the program executable and my-input-file.csv replaced with the name of the input file being used.
Here are two example input files. You can expect any input file to follow this exact format.
The user (aka anyone who runs your program) should see a list of cities to choose from when the program runs, in a numbered list. The user chooses a city by typing its number, presses enter, then the program outputs the calculated boiling point for the user. The print statements (prompts from the program) should match the examples EXACTLY. See “Example Output” below.
In order to calculate the boiling point at altitude, we need to find the pressure at that altitude. This boiling point calculation finds the pressure at altitude assuming that the pressure at sea level is constant and equal to 1013 hPa (1.013 bar). This approximation is sufficient for your coffee making, and you will not take into account the current weather and air pressure.
The formulas for boiling point are:
boiling point = 49.161 * ln(pressure) + 44.932
pressure = 29.921 * (1 - 0.0000068753 * altitude)^ 5.2559
Note that these formulas use specific units:
Let’s say you travelled to Machu Picchu. To calculate the temperature for water to boil for your coffee there, you need to…
pressure = 29.921 * (1 - 0.0000068753 * 7970)^ 5.2559 = 22.25 inHg
boiling point = 49.161 * ln(22.25) + 44.932 = 197.44°F
To calculate the natural log and powers, use the math library by
1
#include <cmath>
The pow() function is used with two parameters, the base and the exponent: pow(base, exponent)
pow(3, 4) is 3 ^ 4 (3 raised to the 4th power).
The log() function returns the natural logarithm (base-e logarithm) of the argument passed in the parameter.
log(5) returns the natural logarithm of 5.
To view all cmath library functions, go to the c++ reference page HERE
Using the City-State-Altitude-1.csv as input:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Boiling Point at Altitude Calculator
1. Leadville
2. Breckenridge
3. Aspen
4. Santa Fe
5. Park City
6. Flagstaff
7. Big Bear Lake
8. Cheyenne
9. Golden
10. Beech Mountain
11. Denver
12. Fort Davis
13. Bozeman
14. Salt Lake City
15. Moab
16. Banner Elk
17. Bend
18. Billings
Enter city number: 1
The boiling point at Leadville is 193.315 degrees Farenheit.
"usage: ./boiling filename"
and exit the program.