I need help with this program

As a first approximation satellites may be presumed to move in circular orbits around their parent (primary) bodies. The velocity of a satellite at sea level for the earth (if this were possible) is Vs = 25830 feet per second (17,600 miles per hour). The velocity necessary to keep a satellite in orbit, known as "circular" velocity Vc, at a distance of h feet above the primary body is Vc -( Vs(sqrt(R))/(sqrt(R+h)), where R is the radius of the primary body (Rearth = 20,903,530 feet). The "parabolic" ("escape") velocity Vp at any particular altitude is equal to the circular velocity times the square root of 2; i.e., Vp=Vc(sqrt(2)). Write a program to compute the circular velocity and the time taken for one orbit of a satellite orbiting the earth a X miles (1 mile = 5280 feet), where X varies between 100 and 300 miles in steps of 10 miles. Also compute the additional velocity that must be imparted to a deep space probe when lanuched from a vehicle orbiting X miles above the surface of the earth. Show all the values in a table format.
This is not a homework site. We won't do your homework for you. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again. As it is impossible to find derivative of function without knowledge in arithmetics, you cannot do more complex tasks in programming without clear understanding of basics
I have tried!

Here is what I have so far:

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const int VELOCITY_SEA_LEVEL = 25830;
const int RADIUS_OF_EARTH = 20903530;
const int FEET_PER_MILE = 5280;

double circularVelocity(int height)
{
return ((double)VELOCITY_SEA_LEVEL * sqrt(RADIUS_OF_EARTH) / sqrt(height));
}
double timeInOrbit(int height, double circular_velocity)
{
// time = distance/rate
return height / circular_velocity;
}

void printOneLine(int height, double velocity, double time, int miles)
{
cout << miles << setprecision(2);
cout << "\t";
cout << height << setprecision(2);
cout << "\t";
cout << velocity << setprecision(2);
cout << "\t";
cout << time << setprecision(2);
cout << "\n";
}

int main()
{
int time;
int height;
double velocity_circular;
double velocity_parabolic;
double time_in_orbit;


// print table headings here

for (int x = 100; x <= 300; x += 5)
{
height = RADIUS_OF_EARTH + (x * FEET_PER_MILE);
velocity_circular = circularVelocity(height);
time_in_orbit = timeInOrbit(height, velocity_circular);
printOneLine(height, circularVelocity(height), timeInOrbit(height, velocity_circular), x);
}

system("PAUSE");
return 0;
}

What problems are you having? You did not say.

Are you using a C++11 compiler? If not, line 12 is going to give you problems. Compilers prior to C++11 do not provide overloads for sqrt(int).

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.


Last edited on
Topic archived. No new replies allowed.