C++ Programming From Problem Analysis To Program Design 8th Edition Malik Test Bank Download
C++ Programming From Problem Analysis To Program Design 8th Edition Malik Test Bank Download
Chapter 8
2. The array index can be any integer less than the array size.
a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 525
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
3. The statement int list[25]; declares list to be an array of 26 components, since the array index starts at 0.
a. True
b. False
ANSWER: False
Chapter 8
POINTS: 1
REFERENCES: 525
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
4. Given the declaration int list[20]; the statement list[12] = list[5] + list[7]; updates the content
of the twelfth component of the array list.
a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 526
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
5. Suppose list is a one dimensional array of size 25, wherein each component is of type int. Further, suppose that
sum is an int variable. The following for loop correctly finds the sum of the elements of list.
sum = 0;
6. If an array index goes out of bounds, the program always terminates in an error.
a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 531
QUESTION TYPE: True / False
Copyright Cengage Learning. Powered by Cognero. Page 2
Name: Class: Date:
Chapter 8
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
7. Arrays can be passed as parameters to a function by value, but it is faster to pass them by reference.
a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 534
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
8. When you pass an array as a parameter, the base address of the actual array is passed to the formal parameter.
a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 539
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
9. The one place where C++ allows aggregate operations on arrays is the input and output of C-strings.
a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 556, 558
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
Chapter 8
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
11. Which of the following statements declares alpha to be an array of 25 components of the type int?
a. int alpha[25]; b. int array alpha[25];
c. int alpha[2][5]; d. int array alpha[25][25];
ANSWER: a
POINTS: 1
REFERENCES: 524
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
12. Assume you have the following declaration char nameList[100];. Which of the following ranges is valid for
the index of the array nameList?
a. 0 through 99 b. 0 through 100
c. 1 through 100 d. 1 through 101
ANSWER: a
POINTS: 1
REFERENCES: 525
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
13. Assume you have the following declaration int beta[50];. Which of the following is a valid element of beta?
a. beta['2'] b. beta['50']
c. beta[0] d. beta[50]
ANSWER: c
POINTS: 1
REFERENCES: 525
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
14. Assume you have the following declaration double salesData[1000];. Which of the following ranges is valid
for the index of the array salesData?
a. 0 through 999 b. 0 through 1000
c. 1 through 1001 d. 1 through 1000
Copyright Cengage Learning. Powered by Cognero. Page 4
Name: Class: Date:
Chapter 8
ANSWER: a
POINTS: 1
REFERENCES: 525
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
15. Suppose that sales is an array of 50 components of type double. Which of the following correctly initializes the
array sales?
a. for (int 1 = 1; j <= 49; j++)
sales[j] = 0;
b. for (int j = 1; j <= 50; j++)
sales[j] = 0;
c. for (int j = 0; j <= 49; j++)
sales[j] = 0.0;
d. for (int j = 0; j <= 50; j++)
sales[j] = 0.0;
ANSWER: c
POINTS: 1
REFERENCES: 528
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
16. Suppose that list is an array of 10 components of type int. Which of the following codes correctly outputs all the
elements of list?
ANSWER: b
Copyright Cengage Learning. Powered by Cognero. Page 5
Name: Class: Date:
Chapter 8
POINTS: 1
REFERENCES: 528
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
a. 0 1 2 3 4 b. 0 5 10 15
c. 0 5 10 15 20 d. 5 10 15 20
ANSWER: c
POINTS: 1
REFERENCES: 528
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
18. What is the value of alpha[2] after the following code executes?
int alpha[5];
int j;
a. 1 b. 4
c. 5 d. 6
ANSWER: c
POINTS: 1
REFERENCES: 528
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
Chapter 8
19. What is the output of the following C++ code?
a. 2 4 6 8 10 b. 4 3 2 1 0
c. 8 6 4 2 0 d. 10 8 6 4 2
ANSWER: d
POINTS: 1
REFERENCES: 528
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
a. 0 5 10 15 20 b. 5 10 15 20 0
c. 5 10 15 20 20 d. Code results in index out-of-bounds
ANSWER: d
POINTS: 1
REFERENCES: 531-532
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
21. Suppose that gamma is an array of 50 components of type int and j is an int variable. Which of the following for
loops sets the index of gamma out of bounds?
a. for (j = 0; j <= 49; j++)
cout << gamma[j] << " ";
b. for (j = 1; j < 50; j++)
cout << gamma[j] << " ";
Chapter 8
c. for (j = 0; j <= 50; j++)
cout << gamma[j] << " ";
d. for (j = 0; j <= 48; j++)
cout << gamma[j] << " ";
ANSWER: c
POINTS: 1
REFERENCES: 531-532
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
22. Consider the following declaration: int alpha[5] = {3, 5, 7, 9, 11};. Which of the following is
equivalent to this statement?
a. int alpha[] = {3, 5, 7, 9, 11};
b. int alpha[] = {3 5 7 9 11};
c. int alpha[5] = [3, 5, 7, 9, 11];
d. int alpha[] = (3, 5, 7, 9, 11);
ANSWER: a
POINTS: 1
REFERENCES: 532
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
24. Which of the following correctly declares name to be a character array and stores "William" in it?
a. char name[6] = "William";
b. char name[7] = "William";
c. char name[8] = "William";
d. char name[8] = 'William';
ANSWER: c
Copyright Cengage Learning. Powered by Cognero. Page 8
Name: Class: Date:
Chapter 8
POINTS: 1
REFERENCES: 554
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
25. Consider the following declaration: char str[15];. Which of the following statements stores "Blue Sky" into
str?
a. str = "Blue Sky";
b. str[15] = "Blue Sky";
c. strcpy(str, "Blue Sky");
d. strcpy("Blue Sky");
ANSWER: c
POINTS: 1
REFERENCES: 554
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
cin.get(charArray, 51);
cin.get(discard);
a. discard = ' ' (Space) b. discard = '!'
c. discard = '\n' d. discard = '\0'
ANSWER: c
POINTS: 1
REFERENCES: 557
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
27. Consider the following statement: double alpha[10][5];. The number of components of alpha is ____.
a. 15 b. 50
Copyright Cengage Learning. Powered by Cognero. Page 9
Name: Class: Date:
Chapter 8
c. 100 d. 150
ANSWER: b
POINTS: 1
REFERENCES: 562
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
28. Consider the statement int list[10][8];. Which of the following about list is true?
a. list has 10 rows and 8 columns.
b. list has 8 rows and 10 columns.
c. list has a total of 18 components.
d. list has a total of 108 components.
ANSWER: a
POINTS: 1
REFERENCES: 562
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
29. Consider the following statement: int alpha[25][10];. Which of the following statements about alpha is
true?
a. Rows of alpha are numbered 0...24 and columns are numbered 0...9.
b. Rows of alpha are numbered 0...24 and columns are numbered 1...10.
c. Rows of alpha are numbered 1...24 and columns are numbered 0...9.
d. Rows of alpha are numbered 1...25 and columns are numbered 1...10.
ANSWER: a
POINTS: 1
REFERENCES: 562
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
30. Which of the following correctly declares and initializes alpha to be an array of four rows and three columns with
the component type int?
a. int alpha[4][3] = {{0,1,2} {1,2,3} {2,3,4} {3,4,5}};
b. int alpha[4][3] = {0,1,2; 1,2,3; 2,3,4; 3,4,5};
c. int alpha[4][3] = {0,1,2: 1,2,3: 2,3,4: 3,4,5};
d. int alpha[4][3] = {{0,1,2}, {1,2,3}, {2,3,4}, {3,4,5}};
Chapter 8
ANSWER: d
POINTS: 1
REFERENCES: 564
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
31. After the following statements execute, what are the contents of matrix?
int matrix[3][2];
int j, k;
a. 0 0 b. 0 1
1 1 2 3
2 2
4 5
c. 0 1 d. 1 1
1 2 2 2
2 3 3 3
ANSWER: c
POINTS: 1
REFERENCES: 568
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
int j;
int sum;
double sale[10][7];
which of the following correctly finds the sum of the elements of the fifth row of sale?
a. sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[5][j];
b. sum = 0;
for(j = 0; j < 7; j++)
Chapter 8
sum = sum + sale[4][j];
c. sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[5][j];
d. sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[4][j];
ANSWER: b
POINTS: 1
REFERENCES: 569
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
int j;
int sum;
double sale[10][7];
which of the following correctly finds the sum of the elements of the fourth column of sale?
a. sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[j][3];
b. sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sale[j][4];
c. sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[j][4];
d. sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[j][3];
ANSWER: d
POINTS: 1
REFERENCES: 569
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
Chapter 8
c. first column is stored first d. first column is stored last
ANSWER: a
POINTS: 1
REFERENCES: 570
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
35. A collection of a fixed number of elements (called components) arranged in n dimensions (n >= 1) is called a(n) ____.
a. matrix b. vector
c. n-dimensional array d. parallel array
ANSWER: c
POINTS: 1
REFERENCES: 575
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
36. In a(n) ____________________ data type, each data item is a collection of other data items.
ANSWER: structured
POINTS: 1
REFERENCES: 522
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
37. The word ____________________ is used before the array declaration in a function heading to prevent the function
from modifying the array.
ANSWER: const
POINTS: 1
REFERENCES: 535
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
38. The ____________________ of an array is the address (that is, the memory location) of the first array component.
ANSWER: base address
POINTS: 1
REFERENCES: 537
Copyright Cengage Learning. Powered by Cognero. Page 13
Name: Class: Date:
Chapter 8
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
39. For a list of length n, the ____________________ sort makes exactly (n(n - 1))/2 key comparisons and 3(n -
1) item assignments.
ANSWER: selection
POINTS: 1
REFERENCES: 551
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM
40. The form of the for loop shown below is called a(n) ____________________ for loop.
for (dataType identifier : arrayName)
statements
ANSWER: range-based
range based
POINTS: 1
REFERENCES: 551-552
QUESTION TYPE: Completion
HAS VARIABLES: False
DATE CREATED: 10/5/2016 1:40 PM
DATE MODIFIED: 10/30/2016 12:46 PM