CMSC104, Spring 2004
Programming Project #6
Bode's Law
Out: Wednesday, April 21, 2004
Due: Monday, May 3, 2004 before midnight
The Objective
This project will give you practice using loops,
the switch, mixing data types and writing functions.
The Background
Mathematicians and other scientists find unexpected applications for
power series approximation. In 1772, the astronomer J. E. Bode proposed
a rule for calculating the distance from the sun to each of the planets
known at that time. To apply that rule, which subsequently became known
as Bode's law, you begin by using the sequence:
b1 = 1, b2 = 3, b3 = 6,
b4 = 12, b5 = 24, b6 = 48
where each subsequent element in the sequence is twice the preceding
one. It turns out that an approximate distance to the ith planet can be
computed from this series by applying the formula
d i = ( 4 + b i ) / 10
The distance is given in astronomical units; an astronomical unit
(AU) is the average distance from the sun to the earth, which is approximately
93,000,000 miles. Except for a disconcerting gap between Mars and Jupiter,
Bode's law gives reasonable approximations for the distances to the seven
planets that were known in Bode's day:
Distance from the Sun
Mercury 0.5 AU 4.650000e+07 miles
Venus 0.7 AU 6.510000e+07 miles
Earth 1.0 AU 9.300000e+07 miles
Mars 1.6 AU 1.488000e+08 miles
? 2.8 AU 2.604000e+08 miles
Jupiter 5.2 AU 4.836000e+08 miles
Saturn 10.0 AU 9.300000e+08 miles
Uranus 19.6 AU 1.822800e+09 miles
Concern about the gap in the sequence led astronomers to discover the
asteroid belt, which they decided was left over after the destruction of
a planet that had once orbited the sun at the distance specified by the
missing entry in Bode's table.
The Task
You are to write a program that calculates each of the distances in both
astronomical units using Bode's formula and the number of miles (shown in
exponential notation), where 1 AU = 93,000,000 miles. You will first need to
calculate the value of the current term in the series. Do this within a
function called GetTermValue. You are not allowed to #define the values of
the terms of the sequence, or hard code these values in any way.
Your program should print out a table exactly like the one shown above.
You'll be expected to write a minimum of four functions, other than
main, for this project.
Here are the function prototypes:
void PrintExplanation (void);
int GetTermValue (int index);
double FindAU (int termValue);
double FindMiles (double au);
Function Descriptions:
- PrintExplanation - should print a message to the user, explaining what
the program will do. Since this function returns nothing, it can also be
called a procedure.
- GetTermValue - This function will take an integer (the index of the term)
as its single argument, index, and return the value of that term in the
sequence. The values of the first two terms in the series are 1 and 3,
respectively. The values of all of the other terms are to be calculated
based on the index of the term. DO NOT HARD CODE THE TERM VALUES
for the terms of index > 2.
- FindAU - This function will take the integer value of a term as its
single argument and, using Bode's formula, calculate the distance
from the sun in astronomical units then return that distance.
- FindMiles - This function will convert astronomical units to miles,
where 1 AU = 93,000,000 miles.
Submitting the Program
To submit the file you should use the command:
submit cs104_0701 Proj6 proj6.c
You can check your submission by using the command:
submitls cs104_0701 Proj6
|