This work must be submitted by 10pm on Friday, October 14. Late work will be accepted until 10am on the following Monday with a 10 point late penalty.
You may talk with other students and instructors about the assignments, but you may not look at or copy code written by others. The penalty for violating this code is an F for the entire semester. M\
As always, all your work must follow these ten essential style items from www.cs.colorado.edu/~main/style.html.
You are the junior astrogation programmer on the USS Field of Dreams, a 2-dimensional starship that is approaching a multi-star system. The captain needs some accurate information about the acceleration due to gravity at various points in the system. "No problem," says the chief astrogation programmer, and she writes these functions that will compute the amount of acceleration that a star (at location (sx,sy)) will generate on a ship (at location (x,y)):
//-----------------------------------------------------------------------------
// The parameters x and y give the location of a spaceship in a
// two-dimensional star field. The parameters sx and sy give the
// location of a star of mass m in this field. The return value
// is the acceleration along the x-axis that the ship feels from
// the star. All distances are in meters and the mass
// is in kilograms. The answer is in m/sec^2.
double accx(double x, double y, double sx, double sy, double m)
{
double dx = (sx - x);
double dy = (sy - y);
double denominator = pow(dx*dx + dy*dy, 1.5);
return G*m*dx/denominator;
}
//----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// The parameters x and y give the location of a spaceship in a
// two-dimensional star field. The parameters sx and sy give the
// location of a star of mass m in this field. The return value
// is the acceleration along the y-axis that the ship feels from
// the star. All distances are in meters and the mass
// is in kilograms. The answer is in m/sec^2.
double accy(double x, double y, double sx, double sy, double m)
{
double dx = (sx - x);
double dy = (sy - y);
double denominator = pow(dx*dx + dy*dy, 1.5);
return G*m*dy/denominator;
}
//----------------------------------------------------------------------------
Notice that the chief took CSCI 1300 at CU, and she
still follows the CSCI 1300 style guide!
Both functions have the same parameters: The x and y coordinates are the location of a ship in the system measured in meters from the point that the astrogator calls the "center.". The coordinates (sx,sy) are the location of a star with mass m (measured in kilograms). The return value of the first function is the acceleration (in Newtons) that the ship feels along the x-axis; and similarly for accy and the y-axis.
"What's G?" you ask.
"You're a silly junior astrogator!" replies the chief. "G is a global named constant for the universal constant of gravity. You'll have to look that up if you don't know its value by heart." (It is 6.673e-11 in the units that we are using!)
The chief takes her functions to the captain, but he bellows, "This does me no good! I have to see a chart!"
"I don't have time to make charts!" replies the chief.
But you do. So, you grab the chief's code for the two functions and say, "I'll be back by 10:00pm on Friday with your charts!"
Your program will produce a chart that looks like this:
Here is how to interpret things: