CS 205 - Programming for the Sciences
Spring 2008 - In-class Exercise for 02/05/08


Today's exercise is to write some programs using arrays to compute statistical values. For this exercise, you are given a C# project with a GUI already created. You are to write the C# code to provide the functionality.


Use a Web browser go to the course webpage http://csserver.evansville.edu/~hwang/s08-courses/cs205.html. Under today's date, save the compressed folder StatisticsInClass.zip. Extract the solution folder. Double-click into the folder Statistics, then double-click on Statistics.sln (the Visual Studio solution file). This will launch Visual Studio with the solution loaded.


The GUI design for the program has been completed. To see it, right-click on Form1.cs in the Solution explorer window and select View Designer.


Assignment (10 points)

1. Double click on the Maximum button. In the handler for this button, write code that will create an array of the user entered values using GetArray. Please note that this version of GetArray simply assigns the created array to a global array variable named elements, so you do not need to declare elements in your handler nor pass an argument to GetArray. That is, to use GetArray, just call it like this:


private void maximum_Click(object sender, EventArgs e)
{
   GetArray();  // Call to create elements array from user input
   :
}


The handler should determine the maximum value stored in the elements array and display in the results listbox: "The maximum value is m", where m is the maximum value.


2. Double click on the Average button. In the handler for this button, write code that will create an array of the user entered values using GetArray, compute the average of the values in the elements array, and display in the results listbox: "The average value is a", where a is the average value.


3. The standard deviation of a collection of numbers is a measure of how much the numbers deviate from the average. The smaller the standard deviation, the closer the numbers are clustered to the average. The standard deviation, S, of a collection of n numbers xi is given by the formula:



whereis the average of the values.


Double click on the Std. Dev. button. In the handler for this button, write code that will create an array of the user entered values using GetArray, compute the standard deviation of the values in the elements array, and display in the results listbox: "The standard deviation is S", where S is the standard deviation. Note that for a C# array, the indexes will be 0 to n-1 rather than 1 to n.

02/04/08 1 of 1