Assignment Four
Arrays

In this assignment you will utilize arrays to print the graph of the sine function. The separate parts of this assignment should all be created in one class, since they are all needed for completion of part four.

Part One

Create a function which returns an array filled with the values of the sine function between zero and 2 pi. This function should take as a parameter an int which tells how many values to put in the array. For example, if this function is called with the number 7, it will return an array of 7 doubles. The first is sine( 0 * (2*pi) / 7), the second is sine( 1 * (2*pi) / 7), the third is sine( 2 * (2*pi) /7)... and the last is sine( 6 * (2*pi) / 7). For a nice accurate value of pi, use the constant Math.PI. To find the sine value for any value, use the Math.sin() function. For example, to find the sine value of 0.2 and place it in a variable named temp, you would call temp = Math.sin( 0.2);.

Part Two

Create a function which prints a histogram of the values stored in an array of ints. This function should take an array of ints as its parameter and return void. It should print a line for each spot in the array, and that line should contain a number of stars equal to the value found in that spot. For example a call to this function with an array of length three, with values 2, 4, 3 contained inside it would result in the following being printed:

**
****
***

Part Three

Create a function which takes an array of doubles and returns an equal sized array of ints. The returned array must be filled with ints which represent the double values in the original array, but scaled so that the smallest double becomes a 1 and the largest double becomes a 50. To calculate the scaling factor, you will need to find the largest double value in the input array and the smallest double value in the input array. Then the scale factor will be 50 divided by (the largest minus the smallest). To calculate the values to be put into the integer array, calculate how much greater the value in the double array is than the smallest double value in the array. Multiply this number by the scale factor and place it into the int array.

Part Four

Putting it together.

Create a function which takes the number of increments to display as a parameter and prints out a graph of the sine function which is that number long. Your main function should either call this function in response to user input or test this function by printing three or four graphs of varying sizes.

What to turn in

Turn in your well-commented source code and a few sample runs of the program at the beginning of class on 26 February, 2007. If you do not complete all the parts of this assignment, please turn in the completed parts along with a main which tests those parts which you have completed.

Alternate Part Two

In order to create a more pleasing graph, create a function which takes two parameters: an array of ints and a single int. The single int represents the zero line. This function should print two stars on each line. One of the stars will be printed in the column indicated in the array, while the other star is printed in the column indicated by the zero-line number.