CS 205 - Programming for the Sciences
Spring 2008 - In-class Exercise for 01/31/08


Today's exercise is to write some programs using arrays. Arrays are covered in Chapter 10 of the textbook. 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, right-click the link to the file ArraysInClass.zip. Save this compressed folder to your network drive. From My Computer, browse to the compressed folder. Right-click on the compressed folder and select Extract All. Go through the steps of the Extraction Wizard ending with a window with the extracted solution folder. Double-click into the folder Arrays, then double-click on Arrays.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. It should look like the following:




The textbox at the top is named array, the small textbox is named input, and the large listbox is named results.


Right-click on Form1.cs in the Solution explorer window and select View Code. All of the following programs should be written in the start_Click button handler as indicated so that they are run when the Start button is clicked. All results should be displayed by adding them to the results listbox items.


  1. Write a program to declare an array of doubles initialized with 10 random values and display them.


  1. Write a program to declare and create an array of 10 doubles, fill each array element with its index value, and display the array elements.


  1. Write a program to declare and create an array of 10 doubles, fill each array element with the square root of its index, and display the array elements.


  1. Write a program to declare and create an array of 10 doubles, fill the array so the element values are in reverse order of the indexes of the array, and display the array elements. I.e., the first element of the array will have value 19, the second will have 18, etc., to the last element of the array having value 0.


  1. Write a program to declare an array variable, call the GetArray method to create an array from user input, and display the array elements. The GetArray method uses the algorithm given previously in the FindRoots exercise to convert a string of values separated by commas into an array of double values.


  1. Write a program to declare an array variable, call the GetArray method to create an array from user input, and iterate through the array displaying only those values that are greater than 10.


  1. Write a program to declare an array variable, call he GetArray method to create an array from user input, get the value of a search target from the input textbox, and iterate through the array displaying the indexes of the positions that contain the search value.


01/30/08 2 of 2