UMBC CMSC104

Programming Project #7

Bode's Law Revisited

Due: Wednesday, December 12, 2001 before midnight


The Objective

This project will give you practice using arrays and passing arrays to functions. You will be able to modify your code from Project 6.

The Background (Same as Project #6)

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 expand on the program you wrote for Project 6 . Instead of calculating each distance and printing out a table of all the planets, you are going to store all of the values in arrays. You will need two arrays, one to store the AU values and one to store the miles values. You will display a menu to the user. The user can then select which planet's information he/she would like to see.

    You'll be expected to write a minimum of seven functions, other than main, for this project.

    Here are the function prototypes:

      void PrintExplanation (void);
      void PrintMenu (void);
      int  GetValidChoice(void);
      int  GetTermValue (int index);
      void FillAUArray (double au[], int size);
      void FillMilesArray(double miles[], double au[], int size);
      void PrintPlanetInfo (int choice, double au[], double miles[]);
      
      

    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.
    • PrintMenu - This function prints a menu to user which lists the planets. See sample output.
    • GetValidChoice - This function gets a number from the user that is between 1 and 8 inclusive. This number is the user's menu choice.
    • 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.
    • FillAUArray - This function fills an array with the AU values for all 8 planets
    • FillMilesArray - This function fills an array with the miles values for all 8 planets.
    • PrintPlanetInfo - This function prints out information about one planet. choice determines which planet is printed.

    Sample Output

    [Your explanation to the user goes here]. 1) Mercury 2) Venus 3) Earth 4) Mars 5) Asteroid Belt 6) Jupiter 7) Saturn 8) Uranus 9) Quit Which planet's information would you like to see? 1 Mercury is the closest planet to the Sun. It is 0.5 astronomical units, which is 4.650000e+07 miles, from the Sun. 1) Mercury 2) Venus 3) Earth 4) Mars 5) Asteroid Belt 6) Jupiter 7) Saturn 8) Uranus 9) Quit Which planet's information would you like to see? 2 Venus is the second planet from the Sun. It is 0.7 astronomical units, which is 6.510000e+07 miles, from the Sun. 1) Mercury 2) Venus 3) Earth 4) Mars 5) Asteroid Belt 6) Jupiter 7) Saturn 8) Uranus 9) Quit Which planet's information would you like to see? 3 Earth is the third planet from the Sun. It is 1.0 astronomical units, which is 9.300000e+07 miles, from the Sun. 1) Mercury 2) Venus 3) Earth 4) Mars 5) Asteroid Belt 6) Jupiter 7) Saturn 8) Uranus 9) Quit Which planet's information would you like to see? 4 Mars is the fourth planet from the Sun. It is 1.6 astronomical units, which is 1.488000e+08 miles, from the Sun. 1) Mercury 2) Venus 3) Earth 4) Mars 5) Asteroid Belt 6) Jupiter 7) Saturn 8) Uranus 9) Quit Which planet's information would you like to see? 5 There is a gap in between Mars and Jupiter. It was discovered to be an asteroid belt. It is 2.8 astronomical units, which is 2.604000e+08 miles, from the Sun. 1) Mercury 2) Venus 3) Earth 4) Mars 5) Asteroid Belt 6) Jupiter 7) Saturn 8) Uranus 9) Quit Which planet's information would you like to see? 9 Thank you for using this program!

    Submitting the Program

    To submit the file you should use the command:

    submit cs104_09 Proj7 proj7.c

    You can check your submission by using the command:

    submitls cs104_09 Proj7


    Last Modified: Tuesday, 04-Dec-2001 18:23:23 EST
    Tuesday, 04-Dec-2001 18:23:23 EST