Skip to document

Drake 5e Test Bank Ch06

Drake Study guide test bank study notes
Course

Intro to C Programming (EECT 128)

3 Documents
Students shared 3 documents in this course
Academic year: 2021/2022
Uploaded by:
0followers
3Uploads
1upvotes

Comments

Please sign in or register to post comments.

Preview text

Test Bank for Prelude to Programming Chapter 6

MULTIPLE CHOICE

  1. A list of related data of the same data type which is referred to by a single variable name with an index number to identify each item is a(n): a. list

b. database c. array d. element ANS: C

2 fourth element of an array named Colors is identified as:

a. Colors[0]

b. Colors[3]

c. Colors[4]

d. Colors[5]

ANS: B

3. Which is the correct way to load an array named WorkHours with the number of hours that

five employees worked last week?

a. Declare WorkHours[5] As Float

Declare J As Integer

For (J = 0; J<=4; J++)

Write “Input number hours worked for employee” + J+

Input WorkHours[J]

End For

b. Declare WorkHours[4] As Float

Declare J As Integer

For (J = 0; J<=4; J++)

Write “Input number hours worked for employee” + J+

Input WorkHours[J+1]

End For

c. Declare WorkHours[5] As Float

Declare J As Integer

For (J = 0; J<=5; J++)

Write “Input number hours worked for employee” + J

Input WorkHours[J+1]

End For

d. None of these are correct ANS: A

  1. Two arrays of the same size in which elements with the same subscript are related are: a. one-dimensional arrays b. two-dimensional arrays c. parallel arrays d. sorted arrays ANS: C

  2. What is displayed when code corresponding to the following pseudocode is executed?

Declare Numbers[12] As Integer

Set K = 0

While K <= 2

Set Numbers[3 * K] = K + 1

Write Numbers[3 * K]

Set K = K + 1

End While

a. 0 3 6

b. 1 2

c. 1 2 3

d. 0 3

ANS: C

  1. What is displayed when code corresponding to the following pseudocode is executed?

Declare B[4] As Float

Set B[3] = 9.

Set K = 0

While K<=

Set B[K] = K/

Write B[K]

Set K = K + 1

End For

a. 0 . 1 1.

b.. 1 1.

c. 0 . 1 9.

d.. 1 1. 9. ANS: A

  1. The following pseudocode searches for an item. Which variable represents a flag to indicate

whether or not the item being searched for has been found? There are N elements in the

array named A.

Input SearchItem

Set X = 0

Set Y = 0

While (Y == 0) AND (X < N – 1)

If A[X] == SearchItem Then

Set Y = 1

End If

Set X = X + 1

13. If a two-dimensional array named Months stores the months of the year in the first

column and the days of each month in the second column, which of the following represents the element that stores March 12, where March is the third month of the year?

a. Months[2, 11] b. Months[3, 11]

c. Months[3, 12] d. Months[2, 12]

ANS: A

14 is the outcome of code corresponding to the following pseudocode?

Declare G[100]

Set N = 4

For (J = 0; J <= N; J++)

Set G[J] = J * 4

End For

Write G[N/2]

Write G[1] + “ “ + G[N–1]

a. 0

4 8

b. 4

8 16

c. 8

4 12

d. 0

1 3

ANS: C

15. A binary search begins by:

a. comparing the search item to all the items in the list or array, on the first pass b. comparing the search item to half the items in the list or array on the first pass c. comparing the search item to the first item in the list or array on the first pass d. creating an index file ANS: B

16. Which of the following is not one of the steps involved to carry out a selection sort which

will sort an array in ascending order?

a. on the first pass, the smallest element is located b. on the first pass, the smallest element is swapped with the first element in the array c. on the first pass, the smallest element is swapped with the last element in the array d. on the second pass, the second-smallest element is located ANS: C

17. Which is the correct way to swap the value of elements K and J in an array named Price?

a. Set Temp = Price[K] Set Price[K] = Price[J] Set Price[J] = Temp

b. Set Temp = Price[K] Set Price[J] = Temp Set Price[K] = Price[J] c. Set Price[K] = Temp Set Price[J] = Price[K] Set Temp = Price[J]

d. Set Price[K] = Temp Set Temp = Price[J] Set Price[J] = Price[K] ANS: A

18. What is the function of a flag in the pseudocode for a binary search?

a. it indicates when all the items in an array have been searched b. it acts as a counter c. it indicates that the item you are searching for has been found d. it is set to 0 to end the program ANS: C

TRUE/FALSE

  1. True/False: The serial search cannot be used with a list of names. ANS: F

  2. True/False: The bubble sort can be used to sort strings. ANS: T

  3. True/False: Arrays are used in input, processing, and output operations. ANS: T

  4. True/False: Arrays save space because all elements of an array are stored in a single memory location while a list of variables needs a separate location for each variable. ANS: F

5. True/False: The following statement: Declare Array1[23] allocates storage space for

22 elements. ANS: F

6. True/False: The following statement: Declare ArrayX[5, 5] allocates storage space

for 25 elements. ANS: T

7. True/False: The third element of an array named Dogs is identified by Dogs[3].

ANS: F

  1. True/False: Parallel arrays are arrays of the same size in which elements of the same subscript are related. ANS: T

  2. True/False: In a serial search, a variable called a flag is often used to indicate whether or not the search has been successful. A flag takes on one of two values. ANS: T

10/False: The bubble sort algorithm sorts data either ascending or descending. ANS: T

11/False: In order to swap the values of two variables, it is necessary to use a third variable as a temporary holding location. ANS: T

  1. The elements of an array are stored in __________ storage locations in the computer’s memory. ANS: consecutive

  2. In parallel arrays, corresponding elements in each array must have the same __________. ANS: subscript (or index number)

  3. The index number of the first element of an array, using the pseudocode of this textbook, is __________. ANS: 0 (zero)

10 item you are looking for when you perform a serial search is known as the __________ _________. ANS: search key

11 a bubble sort arranges a list of names in alphabetical order, from A to Z, the sort is __________ (ascending/descending). ANS: ascending

12 sort an array of ten items with the bubble sort, it will take, at most, __________ passes to completely sort them. ANS: 9

13 __________ operator is used to join two strings. ANS: concatenation

14 __________ function will return the number of characters in a given string. ANS: Length

15 statement Declare MyArray[8,6] allocates __________ consecutive storage

locations in the computer’s internal memory. ANS: 48

  1. A(n) __________ __________ requires that the table keys (the array of data to be searched) is in alphabetical or numerical order. ANS: binary search

17. If an array contains N elements, using the selection sort, it will be sorted after, at most,

__________ passes. ANS: N - 1

18 __________ search method is a good way to search a large amount of data for a search key. ANS: binary

Was this document helpful?

Drake 5e Test Bank Ch06

Course: Intro to C Programming (EECT 128)

3 Documents
Students shared 3 documents in this course
Was this document helpful?
Prelude to Programming Test Bank Chapter 6
Test Bank for Prelude to Programming Chapter 6
MULTIPLE CHOICE
1. A list of related data of the same data type which is referred to by a single variable name with
an index number to identify each item is a(n):
a. list
b. database
c. array
d. element
ANS: C
2. The fourth element of an array named Colors is identified as:
a. Colors[0]
b. Colors[3]
c. Colors[4]
d. Colors[5]
ANS: B
3. Which is the correct way to load an array named WorkHours with the number of hours that
five employees worked last week?
a. Declare WorkHours[5] As Float
Declare J As Integer
For (J = 0; J<=4; J++)
Write “Input number hours worked for employee” + J+1
Input WorkHours[J]
End For
b. Declare WorkHours[4] As Float
Declare J As Integer
For (J = 0; J<=4; J++)
Write “Input number hours worked for employee” + J+1
Input WorkHours[J+1]
End For
c. Declare WorkHours[5] As Float
Declare J As Integer
For (J = 0; J<=5; J++)
Write “Input number hours worked for employee” + J
Input WorkHours[J+1]
End For
d. None of these are correct
ANS: A
© 2011 Pearson Education 1