Chapter 7
C# Programming: From Problem Analysis to Program Design · 16 exercises
Problem 1
The value contained within the square brackets that is used to indicate the length of the array must be a(n): a. class b. double c. string d. integer e. none of the above
3 step solution
Problem 3
Assume an array called num is declared to store four elements.Which of the following statements correctly assigns the value 100 to each of the elements? a. for(x = 0; x < 3; ++x) num [x] = 100 b. for(x = 0; x < 4; ++x) num [x] = 100; c. for(x = 1; x < 4; ++x) num [x] = 100; d. for(x = 1; x < 5; ++x) num [x] = 100; e. none of the above
6 step solution
Problem 4
Choose the statement that does not apply to the following declaration: doubleƒ[ƒ]ƒtotalCostOfItemsƒ=ƒ ƒƒƒƒ{109.95,ƒ169.95,ƒ1.50,ƒ89.95}; a. declares a one-dimensional array of floating-point values b. specifies the size of the array as five c. sets the array element totalCostOfItems [1] to 169.95 d. declares an area in memory where data of double type can be stored e. all are correct
6 step solution
Problem 8
An array is a list of data items that_________ . a. all have the same type b. all have different names c. all are integers d. all are originally set to null ('\0') e. none of the above
3 step solution
Problem 9
Using the following declaration: int [ ] x = {12, 13, 14, 15, 16, 17, 18, 19}; What does x[8] refer to? a. 19 b. 18 c. '\0' d. 0 e. none of the above
4 step solution
Problem 10
Which of the following adds 42 to the element at the fifth physical spot? int [ ] x = {12, 13, 14, 15, 16, 17, 18, 19}; a. x[5] += 42; b. x[4] += 42; c. x[5 + 42]; d. x = 42 + 5; e. none of the above
4 step solution
Problem 11
Which of the following adds 42 to the element at the fifth physical spot? int [ ] x = {12, 13, 14, 15, 16, 17, 18, 19}; a. x[5] += 42; b. x[4] += 42; c. x[5 + 42]; d. x = 42 + 5; e. none of the above
7 step solution
Problem 13
What output is produced by the following code? intƒi; intƒ[ƒ]ƒanArrayƒ=ƒnew intƒ[5]; forƒ(iƒ=ƒ0;ƒiƒ<ƒanArray.Length;ƒi++) ƒƒƒƒƒanArrayƒ[i]ƒ=ƒ2ƒ*ƒi; forƒ(iƒ=ƒ0;ƒiƒ<ƒanArray.Length;ƒi++) ƒƒƒƒƒConsole.Write(anArrayƒ[i]ƒ+ƒ“ƒƒ“); a. 2 2 2 2 2 b. 2 4 6 8 10 c. 0 2 4 6 8 10 d. 0 2 4 6 8 e. none of the above
4 step solution
Problem 19
To convert all the uppercase letters in a string to their lowercase counterpart, you can use the ________ method of the string class. a. IsLower( ) b. ConvertLower( ) c. Lower( ) d. ToLower( ) e. none of the above
8 step solution
Problem 21
Which method in the Array class can be used to get or set the number of elements that an ArrayList can contain? a. Length( ) b. Size( ) c. Dimension( ) d. Rank( ) e. Capacity( )
3 step solution
Problem 22
Which class includes methods to create a dynamic one-dimensional structure? a. Array b. string c. array d. ArrayList e. all of the above
3 step solution
Problem 24
With arrays a limitation on the for each statement is that it can: a. only be used for read-only access b. only be used with integral type arrays c. not be nested d. only be used with arrays smaller than 1000 elements e. not be used with dynamic arrays
8 step solution
Problem 25
A valid call to the following method using a params parameter is: public static voidƒDoSomething(params int[]ƒitem)ƒ a. DoSomething(4); b. DoSomething(anArray); c. DoSomething(4, 5, 6); d. a and c are correct e. all are correct
5 step solution
Problem 26
Use the following string to answer questions a through e. stringƒsValueƒ=ƒ“TodayƒisƒtheƒfirstƒDayƒofƒ“ a. Create a new string that has all lowercase characters except the word Day. Day should be all uppercase. b. Create a new string array that contains the eight elements. Each word from the sValue string should be in a separate array cell. c. Remove the period from the last array element created in Step b. Display the contents of the new array verifying its removal. d. Surround the sValue string with three asterisks on each end. e. Replace the word first with the word best in the sValue string.
5 step solution
Problem 29
Create array declarations for the following problem specifications. a. An array to hold the names of five font strings. Initialize the array with your favorites. b. An array to hold 12 state names. Initialize with the 12 states closest to your campus. c. An array to hold the 10 most common single character middle initials. d. An array to store a key for an exam consisting of 15 true/false questions. e. Parallel arrays to hold up to 100 checking account check numbers, dates, and check amounts.
5 step solution
Problem 30
Explain the difference between the .NET Array class and the ArrayList class.
4 step solution