276 Arrays Chapter 7 g) arrays are maintained (Web server)

276 Arrays Chapter 7 g) arrays are maintained as arrays of arrays. h) A variable must be declared and initialized in the same statement, or a syntax error will occur. i) C# provides the repetition structure for iterating through values in data structures, such as arrays. j) When an invalid array reference is made, an is generated. 7.2 State whether each of the following is true or false. If false, explain why. a) An array can store many different types of values at the same time. b) An array subscript normally should be of data type float. c) An individual array element that is passed to a method and modified in that method will contain the modified value when the called method completes execution. d) The maximum number of comparisons needed for the binary search of any sorted array is the exponent of the first power of 2 greater than the number of elements in the array. e) There are two types of multiple-subscripted arrays square and jagged. f) A const variable must be declared and initialized in the same statement, or a syntax er ror will occur. g) After each comparison, the binary search algorithm eliminates from consideration one third of the elements in the portion of the array that is being searched. h) To determine the number of elements in an array, we can use the NumberOfElements property. i) The linear search method works well for small or unsorted arrays. j) In an m-by-n array, the m stands for the number of columns and the n stands for the num ber of rows. ANSWERS TO SELF-REVIEW EXERCISES 7.1 a) arrays. b) name, type. c) subscript, index or position number. d) sorting. e) searching. f) multiple-subscripted. g.) Jagged. h) const. i) foreach. j) IndexOutofRangeException. 7.2 a) False. An array can store only values of the same type. b) False. An array subscript must be an integer or an integer expression. c) False. For individual primitive-data-type elements of an array, they are passed by value. If a reference to an array element is passed, then modifications to that array element are reflected in the original. An individual element of a reference type is passed to a method by reference. d) True. e) False. The two different types are called rectangular and jagged. f) True. g) False. After each comparison, the binary search algorithm eliminates from consideration half the elements in the portion of the array that is being searched. h) False. To determine the number of elements in an array, we can use the Length property. i) True. j) False. In an m-by-n array, the m stands for the number of rows and the n stands for the number of columns. EXERCISES 7.3 Write statements to accomplish each of the following tasks: a) Display the value of the seventh element of character array f. b) Initialize each of the five elements of single-subscripted integer array gto 8. c) Total the elements of floating-point array c of 100 elements. d) Copy 11-element array ainto the first portion of array bcontaining 34 elements. e) Determine the smallest and largest values contained in 99-element floating-point array w. 7.4 Use a single-subscripted array to solve the following problem: A company pays its salespeople on a commission basis. The salespeople receive $200 per week, plus 9% of their gross sales for that week. For example, a salesperson who grosses $5000 in sales in a week receives $200 plus 9% of $5000, or a total of $650. Write a program (using an array of counters) that determines how many
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Leave a Reply