CS 1400 lab 23: Partially Filled Arrays and the Split Method


The objective of this assignment is to help you better understand how to process partially filled arrays and how to use the Split method.

The Split Method

You will not have to use the Split method to complete this lab, but you will need to know how to use it to complete this week's programming project. You can find a description of the Split method here.

Partially Filled Arrays

Sometimes you will write a program where an array does not get completely filled with data. For example, I might write a grading program that contains an array of student scores big enough to hold 100 values. As long as a class has 100 students in it, my program will work just fine. Of course, most classes will have fewer than 100 students, and my program should work for them as well. To do this, I will have to keep track of how much data is actually stored in the array, and then use this number in any processing that I do on the array. When you pass a partially filled array to a method, you will have to pass the number of values stored in the array as well. The Length property won't work -- in this example, it will always be 100. The foreach loop won't work either, it will process all 100 elements in the array.

Programming Exercise

For this assignment, modify the code that you wrote for lab 22 where the array is summed using a method. However, in this case, compute the product of all of the elements in the array instead. Make sure that your method will handle a partially filled array, by passing the number of values stored in the array as a parameter. When filling the array, allow the user to stop inputting data at any point by typing a zero.


When you submit this lab, add a comment to your submission that answers the following questions.

(1) Why won't using the Length property of an array work correctly when working with the data in a partially filled array?

(2) Why won't a foreach loop work correctly when working with the data in a partially filled array?

File(s) to Submit:

Place your complete project folder in a zip file and name the zip file
lab_23_your-initials_V1.0.zip. For example, I would name my file lab_23_RKD_V1.0.zip. Submit this assignment as Lab #23 on Canvas.

Grading Guidelines

Description Points possible

Assignment meets grading guidelines:
o Source code files contain a declaration that you did not copy any code, except that provided.
o Assignment has been properly submitted to Canvas
o Code meets style guidelines
o Code contains a Console.ReadLine( ) statement at the end


Program contains a method that takes an array as a parameter and handles the partially filled array to correctly find the product of the numbers in the array.


You have correctly answered the questions in this lab.

Total 7