Lab 6 - Arrays

The purpose of this array is to learn array concepts such as valid indices and array processing loops.

Part I: Array "Index out of Bounds" demo

As discussed in class, C++ will happily let you use an invalid subscript to access memory that is not part of the array. The demo, array_example.cpp, shows how one can "clobber" other variables in the program by accessing an invalid subscript. Copy the file to your home directory using the command:
cp /home/fac/melissa/public_html/cs221/demos/array_example.cpp .
Note the period at the end of the cp command, this is critical to get cp to copy the file to your current directory.

Compile and run the program using the following commands:

g++ -o demo array_example.cpp
./demo
You should see how the variables i and min get overwritten by using invalid subscripts for the array. This is why you, as the programmer, must keep track of the size of the array when accessing elements using the subscript operator.

Part II: Assignment

This assignment is a variation on Homework 4, Problem 2. You will write a program that uses a partially filled array to calculate the product of a list of doubles. Note that we are using doubles instead of integers for this lab.

Prompt the user for the number of doubles they wish to enter. Validate that it is a proper size (between 0 and the maximum number of elements for the array). Have one or more for() loops which reads the list of doubles from the keyboard and calculates the product of all the doubles. For example, the product of 2.5, 4.0, 10.0 is 2.5 * 4.0 * 10.0 = 100. Print the product out to the screen.

Name your code lab6.cpp. Email your completed code to me.