C++ Programming From Problem Analysis to Program Design 6th Edition Malik Test Bank download
C++ Programming From Problem Analysis to Program Design 6th Edition Malik Test Bank download
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
Once upon a time, some sixty years ago, on one of the bleakest
points of the coast of Picardy, high perched like a light-house
overhanging the sea, there was a building called the Fortress. You
may see the ruins of it yet. It had been an abbey in olden times, and
credible tales were told of a bearded abbot who “walked” at high
water on the western parapet when the moon was full. One wing of
the Fortress was a ruin at the time this story opens; the other had
braved the stress of time and tempest, and looked out over the sea
defiant as the rock on which it stood. The Caboffs lived in it. Jean
Caboff was a wiry, lithe old man of seventy—a seafaring man every
inch of him. His wealth was boundless, people said, and they also
said that he had gained it as a pirate on the high seas. There was no
proof that this was true; but every one believed it, and the belief
invested Jean Caboff with a sort of wicked prestige which was not
without its fascination in the eyes of the peaceful, unadventurous
population of Gondriac. Caboff had a wife and three sons; the two
eldest were away fighting with Bonaparte on the Rhine; Marcel, the
youngest, was at home. A shy, awkward lad, he kept aloof from the
village boys, never went bird’s-nesting or fishing with them, but
moped like an owl up in his weather-beaten home. They were
unsocial people, the Caboffs; they never asked any one inside their
door; but the few who accidentally penetrated within the Fortress
told wonderful stories of what they saw there; they talked of silken
hangings and Persian carpets, and mirrors and pictures in golden
frames, and marble men and maidens writhing and dancing in
fantastic attitudes; of costly cabinets and jewelled vases, until the
old corsair’s abode was believed to be a sort of enchanted castle.
The stray visitors were too dazzled to notice certain things that
jarred on this profuse magnificence. They did not notice that the
damp had eaten away the gilded cornices, and the rats nibbled
freely at the rich carpets, or that Jean Caboff smoked his pipe in a
high-backed wooden chair, while Mme. Caboff cut out her home-
spun linen on a stout deal table, the two forming a quaint and not
unpicturesque contrast to the silken splendor of their surroundings.
Some five miles inland, beyond a wide stretch of gorse-grown moor,
rose a wood, chiefly of pine-trees, and within the wood, a castle—a
fine old Gothic castle where the De Gondriacs had dwelt for
centuries. The castle and its owners, their grandeur and state and
power, were the pride of the country, every peasant along the coast
for fifty miles knew the history of the lords of Gondriac as well as,
mayhap sometimes better than, he knew his catechism. The family
at present consisted of Rudolf, Marquis de Gondriac, and his son
Hermann. The Marquis was a hale man of sixty; Hermann a
handsome lad of eighteen, who was at college now in Paris, so that
M. le Marquis had no company but his books and his gun in the long
autumn days. He was a silent, haughty man, who lived much alone
and seldom had friends to stay with him. When Hermann was at
home the aspect of the place changed; the château opened its doors
with ancient hospitality, and laughter and music woke up the echoes
of the old halls, and the village was astir as if a royal progress had
halted on the plain; but when Hermann departed things fell back
into the stagnant life he had stirred for a moment. It was natural
that the young man’s holidays were eagerly looked forward to at
Gondriac. But one August came, and, instead of returning home,
Hermann joined a regiment that was on its way to the frontier. He
went off in high-hearted courage as to the fulfilment of his boyish
dreams. M. le Marquis, who had himself served in the guards of the
Comte d’Artois, was proud of his son, of his soldier-like bearing and
manly spirit, and kept the anguish of his own heart well out of sight
as he bade the boy farewell. “I will come back a marshal of France,
father,” was Hermann’s good-by.
Not long after his departure tidings were received of the death of
Hugues Caboff, the old pirate’s eldest son. He had fallen gloriously
on the field of battle; but glory is a sorry salve for broken hearts,
and there was weeping in the Fortress that day—a mother weeping
and refusing to be comforted. Old Jean Caboff bore his grief with an
attempt at stoicism that went far to soften men’s hearts towards him
—farther than his gold, which they said was ill-got, and his charity,
which they called ostentation.
“Who may tell what will come next?” said Peltran, the host of the
village inn.
“They say that M. le Marquis has been over to see the Caboffs,” said
a customer, who dropped in to discuss the event. People felt for the
Caboffs, but, there was no denying it, this sad news was a break in
the dull monotony of Gondriac life.
“I saw his carriage at the foot of the cliff,” said Peltran; “he stayed
full fifteen minutes up at the Fortress. Père Caboff conducted him
down to his carriage, and Marcel stood watching them till it was out
of sight.”
“It must have consoled them mightily to have M. le Marquis come in
and sit talking to them in that neighborly fashion,” remarked lame
Pierre, a hero who had lost a leg and an eye at Aboukir; “that, and
poor Hugues being killed by a cannon-ball under the emperor’s own
eye, ought to cheer up the Caboffs wonderfully.”
“Ay, ay,” said Peltran; “God tempers the wind to the shorn lamb.”
“M. le Marquis looked as down-hearted as if he had lost a child of his
own,” observed Pierre; “may be he was thinking whose turn it might
be next.”
“There goes Mère Virginie with the little one!” said Peltran; and all
present turned their heads towards the window and looked out with
an expression of interest, as if the objects in view were a rare and
pleasant sight. And yet it was one that met them in their daily walks
by the roadside and on the cliff—the little old lady in her nun-like
dress, with her keen gray eyes and sweet smile, and the dark-eyed,
elfin-looking child whose name was Alba. Alba was always singing.
“Is not your little throat tired, my child?” said Virginie, as the blithe
voice kept on soaring and trilling by her side.
“I am never tired singing, petite mère! Do the angels tire of it
sometimes, I wonder?”
“Nay, the angels cannot tire; they are perfectly happy.”
“And I, petite mère—am I not perfectly happy?”
“Is there nothing you long for, nothing you would be the happier for
having?”
“Oh! many things,” cried Alba: “I wish I were grown up; I wish I
were as beautiful as the flowers; I wish I had a voice like the
nightingale—like a whole woodful of nightingales; I wish I lived in a
castle; I wish I were so rich that I might make all the poor people
happy in Gondriac; I wish everybody loved me as you do. Oh! I
should like them all to adore me, petite mère,” cried the child,
clasping her little hands with energy.
“Nay, my child, we must adore none but God; woe to us if we do!”
said Virginie, and her face contracted as with a sudden pain. “But it
seems to me, with so many wishes unfulfilled, you are a long way off
from perfect happiness yet?”
“But I am always dreaming that they are fulfilled, and that does as
well, you know.”
Yes, perhaps it did, Virginie thought, as she bent a wistful smile on
the young dreamer’s face. Alba’s face was full of dreams—beautiful
and passionate, changeful as the sunbeams, tender and strong,
pleading and imperious by turns. How would the dreams evolve
themselves from out that yearning, untamed spirit that shone with a
dangerous light through the dark eyes? Would they prove a mirage,
luring her on to some delusive goal, and leaving her to perish amidst
the golden waste of sands, or would they be a loadstar beckoning
faithfully to a safe and happy destiny?
The child gave promise of rich fruit; her instincts were pure and
true, her heart was tender; but there was a wild element in her
nature that might easily overrule the rest, and work destruction to
herself and others, unless it were reduced in time to serviceable
bondage. Who could tell how this would be—whether the flower
would keep its promise and prove loyal to the bud, or whether the
fair blossom would perish in its bloom, and the tree bring forth a
harvest of bitter fruit?
“It will be as you will it,” a wise man had said to Virginie; “the
destiny of the child is in the hands of the mother, as the course of
the ship is in the hands of the pilot.”
“Then Alba’s will be a happy one!” Virginie replied; “if love be
omnipotent here below, my treasure is safe.”
I.
II.
Low rippling at my feet a loitering stream
Slipt, murmuring music to each listening stone,
Or flung its silver laughter where soft shone
The slant sunbeam breaking the shadows’ dream;
Betwixt the robins’ song the swift blue-bird
Flashed like a heavenly message through the shade
Where with the sunshine gentlest breezes played,
And quiet shadows to soft motion stirred.
Between me and the meadow’s smitten flow’rs
The fresh June roses wreathed the rude fence bars,
Frail elder trailed its galaxy of stars,
While butterflies sped by in golden show’rs—
Far, far beyond, the earth-haze shining through,
Rose the great mountains’ dim and misty blue.
III.
V.
“Take heart, and I thy faltering steps will lead
Above the earth-mists and the brier-strewn road
To my far mountain-tops, the pure abode
Of heaven-born stream, and fair enamelled mead
Whose flow’rs immortal fells not any scythe.
Long have I sought thee 'mid the withering flowers
Wherewith thou smiling crown’dst the fading hours,
Weaving fine fancies 'mid the murmuring blithe
Of lowland stream, and birds, and pattering leaves;
Long have I called thee, waiting for thy voice,
So faint it rose above the troublous noise
Of earthly harvesters among their sheaves;
Long have I waited thy dear heart to win,
So long desired to reign with thee therein.”
VI.
VIII.
The very stones win smoothness from thy feet,
Beneath whose tread immortal flowers spring,
Holding within their snowy hearts no sting,
And breathing spices for love’s incense meet.
The lark, swift rising thy approach to greet,
The fulness of his heavenly song to pour
No higher than thy breast divine need soar,
There hiding life and song in joy complete!
Though sheltering trees o’ershadow not my way
To ward the sultry glow of noonday sun,
Yet 'neath thy cross the coolest shade is won
That dims no ray of that eternal day
That from yon unstained hills of peace doth shine,
Whereto thou leadest me, O Love Divine!
IX.
testbankdeal.com