All work must be submitted by 7:50am on Tuesday, Feb 23. Submit the programming work online to http://culearn.colorado.edu. No late work is accepted, so submit what you have before the due date!
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.
As always, all your work must follow these ten essential style items. See (snowmen.cxx for examples of this style. Also see www.cs.colorado.edu/~main/style.html.
You are the junior astrogation programmer on the USS Field of Dreams, a starship that is approaching a triple 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 two functions that will compute the acceleration at any point in the x-y plane that contains the three stars:
//----------------------------------------------------------------------------
double system_ax(double x, double y)
{
double answer = 0;
answer += (+2 - x)/((x - 2)*(x - 2) + (y + 5)*(y + 5));
answer += (-3 - x)/((x + 3)*(x + 3) + (y - 2)*(y - 2));
answer += (+3 - x)/((x - 3)*(x - 3) + (y - 6)*(y - 6));
return answer;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
double system_ay(double x, double y)
{
double answer = 0;
answer += (-5 - y)/((x - 2)*(x - 2) + (y + 5)*(y + 5));
answer += (+2 - y)/((x + 3)*(x + 3) + (y - 2)*(y - 2));
answer += (+6 - y)/((x - 3)*(x - 3) + (y - 6)*(y - 6));
return answer;
}
//----------------------------------------------------------------------------
Notice that the chief took CSCI 1300 from Michael and Dmitry, and he
still follows the CSCI 1300 style guide!
Both functions have the same
parameters: The x and y coordinates of a location in the system
measured in astronomical units. The output of system_ax
is the acceleration that any object will feel if it is at that
location in astronomical units per second squared (these are massive
stars to generate that kind of force--maybe they are actually black holes!).
She 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 7:50am on Tuesday with your charts!"
Your program will produce a chart that looks like this:
Here is how to interpret things:
system_ax and system_ay to the line's
starting point.
Next week, we will simulate your ship flying through this star field.