www.gibmonks.com

Main Page

[Page 388 (continued)]

### Self-Review Exercises

 7.1 Answer each of the following: Lists and tables of values can be stored in __________ or __________.The elements of an array are related by the fact that they have the same ________ and ___________.The number used to refer to a particular element of an array is called its ________.A(n) __________ should be used to declare the size of an array, because it makes the program more scalable.The process of placing the elements of an array in order is called ________ the array.The process of determining if an array contains a particular key value is called _________ the array.An array that uses two subscripts is referred to as a(n) _________ array. 7.2 State whether the following are true or false. If the answer is false, explain why. An array can store many different types of values.An array subscript should normally be of data type float.If there are fewer initializers in an initializer list than the number of elements in the array, the remaining elements are initialized to the last value in the initializer list.It is an error if an initializer list contains more initializers than there are elements in the array.An individual array element that is passed to a function and modified in that function will contain the modified value when the called function completes execution. 7.3 Write one or more statements that perform the following tasks for and array called fractions: Define a constant variable arraySize initialized to 10.Declare an array with arraySize elements of type double, and initialize the elements to 0.Name the fourth element of the array.[Page 389]Refer to array element 4.Assign the value 1.667 to array element 9.Assign the value 3.333 to the seventh element of the array.Print array elements 6 and 9 with two digits of precision to the right of the decimal point, and show the output that is actually displayed on the screen.Print all the array elements using a for statement. Define the integer variable i as a control variable for the loop. Show the output. 7.4 Answer the following questions regarding an array called table: Declare the array to be an integer array and to have 3 rows and 3 columns. Assume that the constant variable arraySize has been defined to be 3.How many elements does the array contain?Use a for repetition statement to initialize each element of the array to the sum of its subscripts. Assume that the integer variables i and j are declared as control variables.Write a program segment to print the values of each element of array table in tabular format with 3 rows and 3 columns. Assume that the array was initialized with the declaration```int table[ arraySize ][ arraySize ] = { { 1, 8 }, { 2, 4, 6 }, { 5 } }; ```and the integer variables i and j are declared as control variables. Show the output. 7.5 Find the error in each of the following program segments and correct the error: #include ;arraySize = 10; // arraySize was declared constAssume that int b[ 10 ] = { 0 };```for ( int i = 0; <= 10; i++ ) b[ i ] = 1; ```Assume that int a[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } };```a[ 1, 1 ] = 5; ```