C++ Programming From Problem Analysis to Program Design 6th Edition Malik Test Bankdownload
C++ Programming From Problem Analysis to Program Design 6th Edition Malik Test Bankdownload
https://testbankdeal.com/product/c-programming-from-problem-
analysis-to-program-design-6th-edition-malik-test-bank/
https://testbankdeal.com/product/c-programming-from-problem-analysis-
to-program-design-6th-edition-malik-solutions-manual/
https://testbankdeal.com/product/c-programming-from-problem-analysis-
to-program-design-7th-edition-malik-test-bank/
https://testbankdeal.com/product/c-programming-from-problem-analysis-
to-program-design-8th-edition-malik-test-bank/
https://testbankdeal.com/product/pearsons-federal-
taxation-2018-comprehensive-31st-edition-rupert-solutions-manual/
Basic Immunology Functions and Disorders of the Immune
System 4th Edition Abbas Test Bank
https://testbankdeal.com/product/basic-immunology-functions-and-
disorders-of-the-immune-system-4th-edition-abbas-test-bank/
https://testbankdeal.com/product/nonlinear-systems-3rd-edition-khalil-
solutions-manual/
https://testbankdeal.com/product/busn-5-5th-edition-kelly-test-bank/
https://testbankdeal.com/product/guide-to-sql-9th-edition-pratt-
solutions-manual/
https://testbankdeal.com/product/mf-4th-edition-knox-test-bank/
Psychology 1st Edition Marin Test Bank
https://testbankdeal.com/product/psychology-1st-edition-marin-test-
bank/
Chapter 8: Arrays and Strings
TRUE/FALSE
2. The array index can be any integer less than the array size.
3. The statement int list[25]; declares list to be an array of 26 components, since the array
index starts at 0.
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.
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.
7. Arrays can be passed as parameters to a function by value, but it is faster to pass them by reference.
8. When you pass an array as a parameter, the base address of the actual array is passed to the formal
parameter.
9. The one place where C++ allows aggregate operations on arrays is the input and output of C-strings.
MULTIPLE CHOICE
1. Which of the following statements declares alpha to be an array of 25 components of the type int?
a. int alpha[25]; c. int alpha[2][5];
b. int array alpha[25]; d. int array alpha[25][25];
ANS: A PTS: 1 REF: 507-508
2. 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 c. 1 through 100
b. 0 through 100 d. 1 through 101
ANS: A PTS: 1 REF: 509
3. Assume you have the following declaration int beta[50];. Which of the following is a valid
element of beta?
a. beta['2'] c. beta[0]
b. beta['50'] d. beta[50]
ANS: C PTS: 1 REF: 509
4. 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 c. 1 through 1001
b. 0 through 1000 d. 1 through 1000
ANS: A PTS: 1 REF: 509
5. 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;
ANS: C PTS: 1 REF: 512
6. Suppose that list is an array of 10 components of type int. Which of the following codes correctly
outputs all the elements of list?
a. 0 1 2 3 4 c. 0 5 10 15 20
b. 0 5 10 15 d. 5 10 15 20
ANS: C PTS: 1 REF: 512
int alpha[5];
int j;
a. 1 c. 5
b. 4 d. 6
ANS: C PTS: 1 REF: 512
a. 2 4 6 8 10 c. 8 6 4 2 0
b. 4 3 2 1 0 d. 10 8 6 4 2
ANS: D PTS: 1 REF: 512
a. 0 5 10 15 20 c. 5 10 15 20 20
b. 5 10 15 20 0 d. Code results in index out-of-bounds
ANS: D PTS: 1 REF: 515-516
11. 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] << " ";
c. for (j = 0; j <= 50; j++)
cout << gamma[j] << " ";
d. for (j = 0; j <= 48; j++)
cout << gamma[j] << " ";
ANS: C PTS: 1 REF: 515-516
12. 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);
ANS: A PTS: 1 REF: 516
14. 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';
ANS: C PTS: 1 REF: 536
15. 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");
ANS: C PTS: 1 REF: 537
16. Consider the following declaration:
char charArray[51];
char discard;
cin.get(charArray, 51);
cin.get(discard);
17. Consider the following statement: double alpha[10][5];. The number of components of
alpha is ____.
a. 15 c. 100
b. 50 d. 150
ANS: B PTS: 1 REF: 544
18. 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.
ANS: A PTS: 1 REF: 544
19. 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.
ANS: A PTS: 1 REF: 544
20. 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}};
ANS: D PTS: 1 REF: 546
21. After the following statements execute, what are the contents of matrix?
int matrix[3][2];
int j, k;
a. 0 0 c. 0 1
1 1 1 2
2 2 2 3
b. 0 1 d. 1 1
2 3 2 2
4 5 3 3
ANS: C PTS: 1 REF: 548-550
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++)
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];
ANS: B PTS: 1 REF: 550
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];
ANS: D PTS: 1 REF: 551
25. A collection of a fixed number of elements (called components) arranged in n dimensions (n>=1) is
called a(n) ____.
a. matrix c. n-dimensional array
b. vector d. parallel array
ANS: C PTS: 1 REF: 557
COMPLETION
1. A data type is called ____________________ if variables of that type can store only one value at a
time.
ANS: simple
2. In a(n) ____________________ data type, each data item is a collection of other data items.
ANS: structured
double sales[10];
int index;
ANS: sales[index]
4. The word ____________________ is used before the array declaration in a function heading to
prevent the function from modifying the array.
ANS: const
5. The ____________________ of an array is the address (that is, the memory location) of the first array
component.
ANS: base address
6. The ____________________ sort algorithm finds the location of the smallest element in the unsorted
portion of the list and moves it to the top of the unsorted portion of the list.
ANS: selection
7. For a list of length n, the ____________________ sort makes exactly (n(n - 1))/2 key
comparisons and 3(n-1) item assignments.
ANS: selection
ANS:
12
twelve
9. The function ____________________ returns the length of the string s, excluding the null character.
ANS: strlen(s)
ANS: 15
11. The following statements store the value ____________________ into len.
int len;
len = strlen("Sunny California");
ANS: 16
12. The header file string contains the function ____________________,which converts a value of type
string to a null-terminated character array.
ANS: c_str
PTS: 1 REF: 541
13. Two (or more) arrays are called ____________________ if their corresponding components hold
related information.
ANS: parallel
int alpha[10][25];
ANS:
10
ten
15. In the following declaration, the array gamma has ____________________ components.
int gamma[5][6][10];
ANS:
300
three hundred
The irritated, angry editor was running to and fro in the large, light
editorial office of the "N—— Gazette," crumpling in his hand a copy
of the publication, spasmodically shouting and swearing. It was a
tiny figure, with a sharp, thin face, decorated with a little beard and
gold eyeglasses. Stamping loudly with his thin legs, encased in gray
trousers, he fairly whirled about the long table, which stood in the
middle of the room, and was loaded down with crumpled
newspapers, galley-proofs, and fragments of manuscript. At the
table, with one hand resting upon it, while with the other he wiped
his brow, stood the publisher—a tall, stout, fair-haired man, of
middle age, and with a faint grin on his white, well-fed face, he
watched the editor with merry, brilliant eyes. The maker-up, an
angular man, with a yellow face and a sunken chest, in a light-brown
coat, which was very dirty and far too long for him, was shrinking
closely against the wall. He raised his brows, and gazed at the
ceiling with staring eyes, as though trying to recall something, or in
meditation, but a moment later, wrinkled up his nose in a
disenchanted way, and dropped his head dejectedly on his breast. In
the doorway stood the form of the office boy; men with anxious,
dissatisfied countenances kept entering and disappearing, jostling
him on their way. The voice of the editor, cross, irritated, and
ringing, sometimes rose to a squeal, and made the publisher frown
and the maker-up shudder in affright.
"No ... this is such a rascally piece of business! I'll start a criminal
suit against this scoundrel.... Has the proof-reader arrived? Devil
take it,—I ask—has the proof-reader arrived? Call all the compositors
here! Have you told them? No, just imagine, what will happen now!
All the newspapers will take it up.... Dis-grrrace! All Russia will hear
of it.... I won't let that scoundrel off!"
And raising his hands which held the newspaper to his head, the
editor stood rooted to the spot, as though endeavoring to wrap his
head in the paper, and thus protect it from the anticipated disgrace.
"Find him first,..." advised the publisher, with a dry laugh.
"I'll f-find him, sir! I'll f-find him!"—the editor's eyes blazed, and
starting on his gallop once more, and pressing the newspaper to his
breast, he began to tousle it fiercely.—"I'll find him, and I'll roast
him.... And where's that proof-reader?... Aha!... Here.... Now, sir, I
beg that you will favor me with your company, my dear sirs! Hm!...
'The peaceful commanders of the leaden armies ...' ha, ha! Pass in
... there, that's it!"
One after another the compositors entered the room. They already
knew what the trouble was, and each one of them had prepared
himself to play the part of the culprit, in view of which fact, they all
unanimously expressed in their grimy faces, impregnated with lead
dust, complete immobility and a sort of wooden composure. They
huddled together, in the corner of the room, in a dense group. The
editor halted in front of them, with his hands, clutching the
newspaper, thrown behind his back. He was shorter in stature than
they, and he was obliged to hold back his head, in order to look
them in the face. He made this movement too quickly, and his
spectacles flew up on his forehead; thinking that they were about to
fall, he flung his hand into the air to catch them, but, at that
moment, they fell back again on the bridge of his nose.
"Devil take you..." he gritted his teeth.
Happy smiles beamed on the grimy countenances of the
compositors. Someone uttered a suppressed laugh.
"I have not summoned you hither that you may show your teeth at
me!"—shouted the editor viciously, turning livid.—"I should think you
had disgraced the newspaper enough already.... If there be an
honest man among you, who understands what a newspaper is,
what the press is, let him tell who was the author of this.... In the
leading article...." The editor began nervously to unfold the paper.
"But what's it all about?" said a voice, in which nothing but simple
curiosity was audible.
"Ah! You don't know? Well, then ... here ... 'Our factory legislation
has always served the press as a subject for hot discussion ... that is
to say, for the talking of stupid trash and nonsense!...' There, now!
Are you satisfied? Will the man who added that 'talking' be pleased
... and, particularly—the word 'talking'! how grammatical and witty!
—well, sirs, which of you is the author of that 'stupid trash and non-
sense'?"
"Whose article is it? Yours? Well, and you are the author of all the
nonsense that is said in it,"—rang out the same calm voice which
had previously put the question to the editor.
This was insolent, and all involuntarily assumed that the person who
was to blame for the affair had been found. A movement took place
in the hall: the publisher drew nearer to the group, the editor raised
himself on tiptoe, in the endeavor to see over the heads of the
compositors into the face of the speaker. The compositors separated.
Before the editor stood a stoutly-built young fellow, in a blue blouse,
with a pock-marked face, and curling locks of hair which stood up in
a crest above his left temple. He stood with his hands thrust deeply
into the pockets of his trousers, and, indifferently riveting his gray,
mischievous eyes on the editor, he smiled faintly from out of his
curling, light-brown beard. Everybody looked at him:—the publisher,
with brows contracted in a scowl, the editor with amazement and
wrath, the maker-up with a suppressed smile. The faces of the
compositors expressed both badly-concealed satisfaction and alarm
and curiosity.
"So ... it's you?"—inquired the editor, at last, pointing at the pock-
marked compositor with his finger and compressing his lips in a
highly significant manner.
"Yes ... it's I...." replied the latter, grinning in a particularly simple
and offensive manner.
"A-ah!... Very glad to know it! So it's you? Why did you put it in,
permit me to inquire?"
"But have I said that I did put it in?"—and the compositor glanced at
his comrades.
"It certainly was he, Mítry[1] Pávlovitch," the maker-up remarked to
the editor.
[1] Mítry—colloquial abbreviation of Dmítry.—Translator.
testbankdeal.com