Chapter 8

¡Supera tus tareas y exámenes ahora con Quizwiz!

a

A collection of a fixed number of elements (called components) arranged in n dimensions (n>=1) is called a(n) ____. Answers: a. n-dimensional array b. matrix c. parallel array d. vector

d

After the following statements execute, what are the contents of matrix? int matrix[3][2]; int j, k; for (j = 0; j < 3; j++) for (k = 0; k < 2; k++) matrix[j][k] = j + k; Answers: a. 1 1 2 2 3 3 b. 0 1 2 3 4 5 c. 0 0 1 1 2 2 d. 0 1 1 2 2 3

a

All components of an array are of the same data type. Answers: a. True b. False

d

Consider the following declaration: char charArray[51]; char discard; Assume that the input is: Hello There! How are you? What is the value of discard after the following statements execute? cin.get(charArray, 51); cin.get(discard); Answers: a. discard = ' ' (Space) b. discard = '\0' c. discard = '!' d. discard = '\n'

b

Consider the following declaration: char str[15];. Which of the following statements stores "Blue Sky" into str? Answers: a. str[15] = "Blue Sky"; b. strcpy(str, "Blue Sky"); c. strcpy("Blue Sky"); d. str = "Blue Sky";

b

Consider the following statement: double alpha[10][5];. The number of components of alpha is ____. Answers: a. 15 b. 50 c. 100 d. 150

a

Consider the following statement: int alpha[25][10];. Which of the following statements about alpha is true? Answers: 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.

d

Consider the statement int list[10][8];. Which of the following about list is true? Answers: a. list has 8 rows and 10 columns. b. list has a total of 18 components. c. list has a total of 108 components. d. list has 10 rows and 8 columns.

c

Suppose that list is an array of 10 components of type int. Which of the following codes correctly outputs all the elements of list? Answers: a. for (int j = 1; j < 10; j++) cout << list[j] << " "; cout << endl; b. for (int j = 1; j < 11; j++) cout << list[j] << " "; cout << endl; c. for (int j = 0; j <= 9; j++) cout << list[j] << " "; cout << endl; d. for (int j = 1; j <= 10; j++) cout << list[j] << " "; cout << endl;

b

The array index can be any integer less than the array size. Answers: a. True b. False

a

The one place where C++ allows aggregate operations on arrays is the input and output of C-strings. Answers: a. True b. False

a

Assume you have the following declaration char nameList[100];. Which of the following ranges is valid for the index of the array nameList? Answers: a. 0 through 99 b. 0 through 100 c. 1 through 100 d. 1 through 101

a

Assume you have the following declaration double salesData[1000];. Which of the following ranges is valid for the index of the array salesData? Answers: a. 0 through 999 b. 0 through 1000 c. 1 through 1001 d. 1 through 1000

c

Assume you have the following declaration int beta[50];. Which of the following is a valid element of beta? Answers: a. beta['2'] b. beta['50'] c. beta[0] d. beta[50]

b

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. Answers: a. True b. False

b

Given the following declaration: 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? Answers: a. sum = 0; for(j = 0; j < 7; j++) sum = sum + sale[j][3]; b. sum = 0; for(j = 0; j < 10; j++) sum = sum + sale[j][3]; c. sum = 0; for(j = 0; j < 10; j++) sum = sum + sale[j][4]; d. sum = 0; for(j = 0; j < 7; j++) sum = sum + sale[j][4];

d

Given the following declaration: 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? Answers: a. sum = 0; for(j = 0; j < 10; j++) sum = sum + sale[4][j]; b. sum = 0; for(j = 0; j < 7; j++) sum = sum + sale[5][j]; c. sum = 0; for(j = 0; j < 10; j++) sum = sum + sale[5][j]; d. sum = 0; for(j = 0; j < 7; j++) sum = sum + sale[4][j];

b

If an array index goes out of bounds, the program always terminates in an error. Answers: a. True b. False

b

In C++, the null character is represented as ____. Answers: a. '0' b. '\0' c. "\0" d. "0"

a

In a two-dimensional array, the elements are arranged in a table form. Answers: a. True b. False

c

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? Answers: a. for (j = 0; j <= 49; j++) cout << gamma[j] << " "; b. for (j = 0; j <= 48; j++) cout << gamma[j] << " "; c. for (j = 0; j <= 50; j++) cout << gamma[j] << " "; d. for (j = 1; j < 50; j++) cout << gamma[j] << " ";

d

In row order form, the ____. Answers: a. first column is stored last b. first column is stored first c. first row is stored last d. first row is stored first

b

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; for (int i = 0; i < 25; i++) sum = sum + list; Answers: a. True b. False

b

The statement int list[25]; declares list to be an array of 26 components, since the array index starts at 0. Answers: a. True b. False

c

What is the output of the following C++ code? int list[5] = {0, 5, 10, 15, 20}; int j; for (j = 0; j < 5; j++) cout << list[j] << " "; cout << endl; Answers: a. 0 1 2 3 4 b. 0 5 10 15 c. 0 5 10 15 20 d. 5 10 15 20

d

What is the output of the following C++ code? int list[5] = {0, 5, 10, 15, 20}; int j; for (j = 1; j <= 5; j++) cout << list[j] << " "; cout << endl; Answers: 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

d

What is the output of the following C++ code? int alpha[5] = {2, 4, 6, 8, 10}; int j; for (j = 4; j >= 0; j--) cout << alpha[j] << " "; cout << endl; Answers: a. 2 4 6 8 10 b. 4 3 2 1 0 c. 8 6 4 2 0 d. 10 8 6 4 2

a

When you pass an array as a parameter, the base address of the actual array is passed to the formal parameter. Answers: a. True b. False

a

Which of the following correctly declares and initializes alpha to be an array of four rows and three columns with the component type int? Answers: 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};

b

Which of the following correctly declares name to be a character array and stores "William" in it? Answers: a. char name[7] = "William"; b. char name[8] = "William"; c. char name[6] = "William"; d. char name[8] = 'William';


Conjuntos de estudio relacionados

Ch. 9 Microbiology Assignment Questions

View Set

BIO - CHAPTER 7 The Skeletal System: The Axial Skeleton

View Set

OT Test Two Chapters 15-18 Study Questions

View Set

Medsurg Respiratory & HIV/Ebola/Corona

View Set

Forensic Anthropology Exam 3 Review

View Set

Exam #1. drug addiction counseling, Coccia

View Set