/* Author: SJL As3 Date: 2008-02-10 */ #include #include #include using namespace std; const double EARTH_GRAVITY = 9.8; const double MOON_GRAVITY = 1.67; const double MARS_GRAVITY = 3.71; void printOutput(string where, double h, double t, double d); double hitDistance(double v, double a, double t); double airTime(double v, double a, double g); double getMaxHeight(double v, double g); double degreesToRadians(double degrees); int main(){ cout << "Enter initial velocity" << endl; double v0; cin >> v0; cout << "Enter initial hit angle" << endl; double a0; cin >> a0; a0 = degreesToRadians(a0); double height, time, distance; height = getMaxHeight(v0, EARTH_GRAVITY); time = airTime(v0, a0, EARTH_GRAVITY); distance = hitDistance(v0, a0, time); printOutput("On Earth", height, time, distance); height = getMaxHeight(v0, MARS_GRAVITY); time = airTime(v0, a0, MARS_GRAVITY); distance = hitDistance(v0, a0, time); printOutput("On Mars", height, time, distance); height = getMaxHeight(v0, MOON_GRAVITY); time = airTime(v0, a0, MOON_GRAVITY); distance = hitDistance(v0, a0, time); printOutput("On the Moon", height, time, distance); return 0; } double degreesToRadians(double degrees){ return degrees * 0.0174532925; } double getMaxHeight(double v, double g){ return (v * v)/(2 * g); } double airTime(double v, double a, double g){ return (2.0 * v * sin(a))/(g/2.0); } double hitDistance(double v, double a, double t){ return (v * cos(a) * t); } void printOutput(string where, double h, double t, double d){ cout << where << endl; cout << "\t Max Height : " << h << endl; cout << "\t Travel time: " << t << endl; cout << "\t Distance : " << d << endl; return; }