CS 210 – Fundamentals of Programming I
Spring 2007 – Homework 4
20 points
Out: February 20/21
Due: February 27/28 (same day as the practical exam)


1. (4 points) Write C++ variable declarations for the following arrays:


a. An array with capacity 10 in which each element is an integer.

b. An array whose indices are integers 0 through 10 and in which each element is a real value.

c. An array that can store 40 characters.

d. An array that can store 100 values, each of which is either true or false.


2. (6 points) Write C++ variable declarations and code fragments to initialize the following arrays:


a. An array whose indices are the integers 0 through 99 and in which the value stored in each element is the same as its index.

b. An array whose indices are the integers 0 through 99 and in which the value stored in the elements are the indices in reverse order. That is, the value stored at index 0 is 99 and the value stored at index 99 is 0.

c. An array of capacity 50 in which the value stored in an element is true if the corresponding index is even and false otherwise.


3. (10 points) We would like a function Range that receives an array of reals and the number of elements stored in the array, and returns the range of values stored in the array; that is, the difference between the largest value and the smallest value stored in the array. Note that this function should not change the array.


a. Write an analysis and design for this function.

b. Write the C++ function definition for your analysis and design.


02/19/07 1