Created
September 20, 2017 08:18
-
-
Save PhilipCastiglione/568a1e62b4eec2c0fca7ac29996e622b to your computer and use it in GitHub Desktop.
A program that calculates the distance a hot air ballon has to travel to circumnavigate the globe.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A short program to calculate the approximate length of a journey around the | |
* globe in a hot air balloon. | |
* | |
* Authored by Philip Castiglione | |
*/ | |
#include "splashkit.h" | |
using namespace std; | |
#define PI 3.14159 // PI to 5 decimal places | |
#define FEET_CMS 30.48 // centimeters in a foot | |
#define RADIUS_OF_EARTH 6371 // radius of earth in kilometers | |
/** | |
* Convert a distance in feet to kilometers. | |
* | |
* @params distance The distance in feet | |
*/ | |
void convert_feet_to_kms(double &distance) | |
{ | |
distance *= FEET_CMS; // convert distance from feet to cms | |
distance /= 100; // convert distance from cms to meters | |
distance /= 1000; // convert distance from meters to kms | |
} | |
/** | |
* Calculate a circumference given a radius. | |
* | |
* @param radius The radius of a cirle (or sphere) | |
* @returns circumference The circumference of the circle | |
*/ | |
double calculate_circumference(double radius) | |
{ | |
return 2 * PI * radius; | |
} | |
/** | |
* Calculate the distance around the earth in a hot air balloon. | |
* | |
* @returns distance The distance around the earth in the balloon | |
*/ | |
double calculate_distance() | |
{ | |
double altitude, total_radius, distance; | |
altitude = 2000.0; // altitude of the balloon in feet | |
convert_feet_to_kms(altitude); | |
total_radius = RADIUS_OF_EARTH + altitude; | |
distance = calculate_circumference(total_radius); | |
return distance; | |
} | |
int main() | |
{ | |
double total_distance; | |
total_distance = calculate_distance(); | |
write_line("The total distance travelled in kms will be: " + | |
to_string(total_distance)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment