Homework 09
Version 1

 

Due by 8:00 AM on Monday, November 1, 1999

In this assignment you will write a collection of functions that manipulate arrays in ways typically required for statistical analysis. This will be done in the setting of a simple grading program.

The program, which should be named Grading, begins by prompting the user for the number of grades to be manipulated. The user is then prompted to enter that many grades, and they are stored in the array. The grades are floating point values between 0 and 100 (inclusive). If they enter a grade that is out of range, go into a correction loop until they enter a valid grade.

The program then displays the following menu of options for the user:

	1 Display Grades
	2 Compute Average of Grades
	3 Compute Standard Deviation of Grades
	4 Display Position and Value of Lowest Grade
	5 Display Position and Value of Highest Grade
 
	9 Quit
If the user picks a valid choice, that action should be performed. Otherwise an error should be displayed. In either case, the menu should then be redisplayed and the process repeated, until the user chooses the Quit option.

Here is a sample run of the program. You should try to make your program mimic as closely as possible the behavior of the sample run.

The main method of your solution should include the code for inputting the initial data, followed by a loop that displays the menu (using a method defined below), get's the user's choice, and processes it using a switch statement which picks among the appropriate actions.

Your code should print floating point numbers with exactly two digits after the decimal point.

Your solution should include and make use of at least the following methods (we have given the method headers, but have only given the types of the formal parameters, not their names):

  1. public static void displayMenu()
    Displays the text of the menu of choices.

  2. public static void displayData(double [])
    Displays a nicely formatted report of the current data set. Each grade is numbered (starting at 1, which is how the user thinks of them being numbered) and printed on its own line.

    Note: Methods 3 through 7 should NOT interact with the user at all. They should only communicate with the method that calls them.

  3. public static double sumArray(double[])
    Returns the sum of the elements in the array.

  4. public static double averageArray(double[])
    Computes and returns the average of the elements in the array. Calls the sumArray function to do most of the work.

  5. public static double stdDevArray(double[])
    Computes and returns the standard deviation of the elements in the array. Calls the averageArray function to do some of the work.

  6. public static int indexOfSmallest(double[])
    Returns the index of the smallest value in the array. Thus, if the array contains 5 3 9 6 4 this function should return 1 which is the index of the value 3 (since the 5 is in index 0).

    Note, however, when main displays the result for the user, it should say that the 3 is in position 2, since that is how the user thinks of them being numbered.

    If there is more than one occurence of the smallest value, the position of the first occurence of that value should be returned.

  7. public static int indexOfLargest(double[])
    Returns the index of the largest value in the array. If there is more than one occurence of the largest value, the position of the first occurence of that value should be returned. As with the last routine, when main displays the position for the user, it should be adjusted to the user's perspective.

Last modified August 28 for Fall 99 cs5 by fleck@cs.hmc.edu


This page copyright ©1998 by Joshua S. Hodas. It was built with Frontier on a Macintosh . Last rebuilt on Tue, Oct 20, 1998 at 5:01:56 PM.
http://www.cs.hmc.edu/~hodas/courses/cs5/week_09/homework.html