Professional Documents
Culture Documents
C++ For Engineers and Scientists 4th Edition Bronson Test Bank 1
C++ For Engineers and Scientists 4th Edition Bronson Test Bank 1
Chapter 7: Arrays
TRUE/FALSE
3. Array elements can be initialized in their declaration statements in the same manner as scalar variables,
except that the initializing elements must be included in braces.
5. Two-dimensional array variables can be used anywhere that scalar variables are valid.
7. It is generally advisable to use the size of the array in a function header line.
8. Arrays are extremely useful in any application that requires multiple passes through the same set of
data elements.
10. Using a subscript that references a nonexistent array element will always be detected by all C++
compilers.
MULTIPLE CHOICE
1. A(n) ____ variable is one whose value can’t be further subdivided or separated into a legitimate data
type.
a. indexed c. grade
b. array d. scalar
ANS: D PTS: 1 REF: 385
2. A(n) ____ is a list of related values, all having the same data type, that’s stored with a single group
name.
a. static variable c. atomic variable
b. one-dimensional array d. instance variable
ANS: B PTS: 1 REF: 386
4. The element’s index or ____ value gives the element’s position in the array.
a. id c. subscript
b. scale d. reference
ANS: C PTS: 1 REF: 387-388
5. Each individual array element is referred to as an indexed variable or a(n) ____ variable.
a. scalar c. static
b. subscripted d. array
ANS: B PTS: 1 REF: 388
6. A(n) ____ type is any type whose values can be decomposed and are related by some defined
structure.
a. scalar c. aggregate
b. static d. atomic
ANS: C PTS: 1 REF: 390
7. A(n) ____ check is a check of the value of the index being used.
a. index c. object
b. bounds d. reference
ANS: B PTS: 1 REF: 391
10. A(n) ____ array consists of both rows and columns of elements.
a. one-dimensional c. single-dimensional
b. two-dimensional d. simple-dimensional
ANS: B PTS: 1 REF: 399
12. ____ loops are especially useful when dealing with two-dimensional arrays because they allow the
programmer to designate and cycle through each element easily.
a. Nested c. Simple
b. Single d. Conditional
ANS: A PTS: 1 REF: 402
14. To meet the need of providing a tested and generic set of data structures that can be modified,
expanded, and contracted, C++ includes a useful set of classes in its ____.
a. Standard Array Library c. Standard Data Structure Library
b. Standard Template Library d. Data Structure Library
ANS: B PTS: 1 REF: 432
15. Each STL class is coded as a template that permits the constructing a generic data structure, referred to
as a(n) ____.
a. container c. structure
b. object d. array
ANS: A PTS: 1 REF: 432
16. The STL algorithm ____ returns the sum of the numbers in a specified range.
a. count c. max
b. sum d. accumulate
ANS: D PTS: 1 REF: 435
17. The STL algorithm ____ copies elements from a source range to a destination range.
a. copy c. copy_forward
b. copy_backward d. replace
ANS: A PTS: 1 REF: 435
18. The STL algorithm ____ assigns every element in a specified range to a specified value.
a. equal c. find
b. fill d. unique
ANS: B PTS: 1 REF: 435
19. The STL algorithm ____ randomly shuffles element values in a specified range.
a. random c. shuffle
b. rnd_shuffle d. random_shuffle
ANS: D PTS: 1 REF: 435
20. The STL algorithm ____ removes duplicate adjacent elements in a specified range.
a. duplicate c. unique
b. delete d. remove
ANS: C PTS: 1 REF: 435
21. ____ are used to specify which elements in a container are to be operated on when an algorithm is
called.
a. Iterators c. Sequencers
b. Walkers d. Indexers
ANS: A PTS: 1 REF: 436
22. A(n) ____ is the data structure of first choice when you have a list of primitive data types or objects
that can be grouped as an array but must be expanded or contracted.
a. array c. object
b. vector d. class
ANS: B PTS: 1 REF: 436
23. The ____ header is required to create one or more vector objects.
a. <string> c. <algorithm>
b. <iostream> d. <vector>
ANS: D PTS: 1 REF: 436
24. The STL ____ function returns a value corresponding to the start of the vector.
a. begin() c. rear()
b. end() d. last()
ANS: A PTS: 1 REF: 439
25. Many compilers automatically set all elements of integer and real value arrays to ____.
a. -100 c. -1
b. -10 d. 0
ANS: D PTS: 1 REF: 455
COMPLETION
1. Good programming practice requires defining the number-of-items in the array as a(n)
____________________ before declaring the array.
ANS: constant
ANS:
0
zero
3. Internally, the computer uses the ___________________ as an offset from the array’s starting position.
ANS: index
ANS: cout
5. The ____________________ of an array may be omitted when initializing values in the declaration
statement.
ANS:
size
length
LIGHT. ¹
( .)
This is one of the last poems. It was written after the death of her sister Alice, in 1871.
I would recapture—
As it of old befell,
WIFE TO HUSBAND. ¹
NEXT YEAR.
HE lark is singing gaily in the meadow, the sun is rising o’er the
dark blue hills;
But she is gone, the music of whose talking was
sweeter than the voice of summer rills.
I see the sunbeams trail along the orchard, and fall in thought
to tangling up her hair;
More lofty than the skies that bend and brighten o’er us, more
constant than the dove.
Next year, when larks are singing gaily in the meadow, I shall
not hear their tone;
But she in the dim, far-off country of the stranger, will walk no
more alone.
MY MOTHER’S PICTURE.
( “ .”)
WASHINGTON IRVING.
.
It was on the 3rd of April, 1783, when the British were in possession of
New York City and George Washington was exerting his forces to drive them
away, that young Irving was born. Like Benjamin Franklin, he was the
youngest of many sons. His father was a Scotchman and his mother an
Englishwoman, who emigrated to America soon after their marriage and
settled in New York about the year 1770. The Irvings were staunch patriots
and did what they could to relieve the sufferings of American prisoners
while the British held the city, and their son was not christened until the
English evacuated the town and George Washington came in and took
possession. In her exultation over this event Mrs. Irving exclaimed:
“Washington’s work is ended and this child shall be named after him.” Six
years later, in 1789, George Washington took the oath of office as the first
President of the United States, in New York, which was then the capital of
the country. Shortly after this the Scotch servant girl with little Irving in
charge, seeing the President on the street called out: “Please, your honor,
here’s a bairn was named after you.” Washington bade her bring the boy to
him, and placing his hands on his head gave him his blessing.
As a boy Irving was playful rather than studious. His delicate health
prevented his entering college, and the educational training which he
received was at sundry small schools, and this ceased at the age of sixteen, at
which time he began to study law. Irving’s opportunity came in 1802, when
his brother, Dr. Peter Irving, established a daily paper, to which Washington,
then only nineteen, contributed a series of essays under the signature of
“Jonathan Oldstyle.” They were written in a humorous vein and met an
instant success, being quoted and copied as far and wide as the sayings of
Benjamin Franklin’s “Poor Richard” had been fifty years before.
During the last two years of Irving’s stay abroad he was Secretary of the
United States Legation at London, and on his return to America in 1832 was
received with great public honor. His books now brought him an adequate
income, and he built for himself a handsome villa at Irvington, New York—
which he named “Sunnyside”—where he continued to reside until his death,
with the exception of four years (1842–46), during which time he
represented the United States at the Court of Madrid. While residing at
Sunnyside he wrote the “Tours of the Prairies” (1835); “Astoria” (1836);
“Adventures of Captain Bonneville” (1837). After his return from the Court
of Spain he edited a new edition of his complete works, issued in 1850. He
also published in 1849 and 1850 “Oliver Goldsmith: a Biography,” and
“Mahomet and His Successors.” From 1850 to 1859 he published only two
books, namely, “♦Wolfert’s Roost and Other Papers” and the “Life of George
Washington;” the latter issued just before his death, which occurred at
Sunnyside, November 28, 1859. His nephew, P. H. Irving, afterwards
prepared the “Life and Letters of Washington Irving” (1863), and also edited
and published his “Spanish Papers and Other Miscellanies” (1866.)
That Irving never married may be attributed to the fact that his fiancé,
Miss Matilda Hoffman, a charming and beautiful girl, to whom he was
devotedly attached, died suddenly soon after they were engaged. Irving, then
twenty-six, bore the blow like a man, but he carried the scar through life.
The genius of Irving was not of that stalwart, rugged character which
conquered by admiration. It rather won its way softly and by the aid of genial
sentiment, human sympathy and pungent humor. His heart was quick to
catch the sentiment, and his imagination as quick to follow the thread of an
incident to its most charming conclusion. He it was who peopled the green
nooks of “Sleepy Hollow” and the rocky crags of the Catskills, describing
landscape and character with a charm which no later American writer has
surpassed; and it was his delicate subtlety and keen insight which called into
being in his “Knickerbocker’s History” a civilization, giving to the legend
the substance of truth, and presenting a fiction so that it passed for a fact.
This is a feat which very few authors have accomplished.
The poet, Lowell, in his “Fable for Critics,” thus happily characterizes
Washington Irving:
From the warm lazy sun loitering down through green leaves,
HE sound of casual footsteps had ceased from the abbey. I could only
hear, now and then, the distant voice of the priest repeating the
evening service, and the faint responses of the choir; these paused for
a time, and all was hushed. The stillness, the desertion and obscurity
that were gradually prevailing around, gave a deeper and more
solemn interest to the place:
Suddenly the notes of the deep-laboring organ burst upon the ear, falling with
double and redoubled intensity, and rolling, as it were, huge billows of sound. How
well do their volume and grandeur accord with this mighty building! With what pomp
do they swell through its vast vaults, and breathe their awful harmony through these
caves of death, and make the silent sepulchre vocal! And now they rise in triumph and
acclamation, heaving higher and higher their accordant notes, and piling sound on
sound. And now they pause, and the soft voices of the choir break out into sweet
gushes of melody; they soar aloft, and warble along the roof, and seem to play about
these lofty vaults like the pure airs of heaven. Again the pealing organ heaves its
thrilling thunders, compressing air into music, and rolling it forth upon the soul. What
long-drawn cadences! What solemn sweeping concords! It grows more and more
dense and powerful—it fills the vast pile, and seems to jar the very walls—the ear is
stunned—the senses are overwhelmed. And now it is winding up in full jubilee—it is
rising from the earth to heaven—The very soul seems rapt away and floated upwards
on this swelling tide of harmony!
I sat for some time lost in that kind of reverie which a strain of music is apt
sometimes to inspire: the shadows of evening were gradually thickening round me; the
monuments began to cast deeper and deeper gloom; and the distant clock again gave
token of the slowly waning day.
As the enraptured Ichabod fancied all this, and as he rolled his great green eyes
over the fat meadowlands, the rich fields of wheat, of rye, of buckwheat, and Indian
corn, and the orchards burdened with ruddy fruit, which surrounded the warm
tenement of Van Tassel, his heart yearned after the damsel, who was to inherit those
domains, and his imagination expanded with the idea, how they might be readily
turned into cash, and the money invested in immense tracts of wild land and shingle
palaces in the wilderness.
Nay, his busy ♦ fancy already realized his hopes, and presented to him the
blooming Katrina, with a whole family of children, mounted on the top of a wagon
loaded with household trumpery, with pots and kettles dangling beneath; and he
beheld himself bestriding a pacing mare, with a colt at her heels, setting out for
Kentucky, Tennessee, or the Lord knows where.
COLUMBUS AT BARCELONA.
( “ .”)
To receive him with suitable pomp and distinction, the sovereigns had ordered
their throne to be placed in public, under a rich canopy of brocade of gold, in a vast
and splendid saloon. Here the king and queen awaited his arrival, seated in state, with
the Prince Juan beside them, and attended by the dignitaries of their court, and the
principal nobility of Castile, Valencia, Catalonia, and Aragon, all impatient to behold
the man who had conferred so incalculable a benefit upon the nation. At length
Columbus entered the hall, surrounded by a brilliant crowd of cavaliers, among whom,
says Las Casas, he was conspicuous for his stately and commanding person, which,
with his countenance rendered venerable by his gray hairs, gave him the august
appearance of a senator of Rome. A modest smile lighted up his features, showing that
he enjoyed the state and glory in which he came, and certainly nothing could be more
deeply moving to a mind inflamed by noble ambition, and conscious of having greatly
deserved, than these testimonials of the admiration and gratitude of a nation or rather
of a world. As Columbus approached, the sovereigns rose, as if receiving a person of
the highest rank. Bending his knees, he offered to kiss their hands; but there was some
hesitation on their part to permit this act of homage. Raising him in the most gracious
manner, they ordered him to seat himself in their presence; a rare honor in this proud
and punctilious court.
At their request he now gave an account of the most striking events of his voyage,
and a description of the islands discovered. He displayed specimens of unknown birds
and other animals; of rare plants of medicinal and aromatic virtues; of native gold in
dust, in crude masses, or labored into barbaric ornaments; and, above all, the natives of
these countries, who were objects of intense and inexhaustible interest. All these he
pronounced mere harbingers of greater discoveries yet to be made, which would add
realms of incalculable wealth to the dominions of their majesties, and whole nations of
proselytes to the true faith.
When he had finished, the sovereigns sank on their knees, and, raising their
clasped hands to heaven, their eyes filled with tears of joy and gratitude, poured forth
thanks and praises to God for so great a providence; all present followed their
example; a deep and solemn enthusiasm pervaded that splendid assembly, and
prevented all common acclamations of triumph. The anthem Te Deum laudamus,
chanted by the choir of the royal chapel, with the accompaniment of instruments, rose
in full body of sacred harmony, bearing up as it were the feelings and thoughts of the
auditors to heaven, “so that,” says the venerable Las Casas, “it seemed as if in that
hour they communicated with celestial delights.” Such was the solemn and pious
manner in which the brilliant court of Spain celebrated this sublime event; offering up
a grateful tribute of melody and praise, and giving glory to God for the discovery of
another world.
It was the very witching time of night that Ichabod, heavy-hearted and crestfallen,
pursued his travels homewards, along the sides of the lofty hills which rise above
Tarrytown, and which he had traversed so cheerily in the afternoon. The hour was as
dismal as himself. Far below him the Tappan Zee spread its dusk and indistinct waste
of waters, with here and there the tall mast of a sloop riding quietly at anchor under the
land. In the dead hush of midnight he could even hear the barking of the watch-dog
from the opposite shore of the Hudson; but it was so vague and faint as only to give an
idea of his distance from this faithful companion of man. Now and then, too, the long-
drawn crowing of a cock, accidentally awakened, would sound far, far off, from some
farmhouse away among the hills—but it was like a dreaming sound in his ear. No
signs of life occurred near him, but occasionally the melancholy chirp of a cricket, or
perhaps the guttural twang of a bullfrog, from a neighboring marsh, as if sleeping
uncomfortably, and turning suddenly in his bed.
All the stories of ghosts and goblins that he had heard in the afternoon now came
crowding upon his recollection. The night grew darker and darker, the stars seemed to
sink deeper in the sky, and driving clouds occasionally hid them from his sight. He had
never felt so lonely and dismal. He was, moreover, approaching the very place where
many of the scenes of the ghost stories had been laid. In the centre of the road stood an
enormous tulip-tree, which towered like a giant above all the other trees of the
neighborhood, and formed a kind of landmark. Its limbs were gnarled and fantastic,
large enough to form trunks for ordinary trees, twisting down almost to the earth and
rising again into the air. It was connected with the tragical story of the unfortunate
André, who had been taken prisoner hard by; and was universally known by the name
of Major André’s tree. The common people regarded it with a mixture of respect and
superstition, partly out of sympathy for the fate of its ill-starred namesake, and partly
from the tales of strange sights and doleful lamentations told concerning it.
About two hundred yards from the tree a small brook crossed the road, and ran
into a marshy and thickly-wooded glen, known by the name of Wiley’s Swamp. A few
rough logs, laid side by side, served for a bridge over this stream. On that side of the
road where the brook entered the wood, a group of oaks and chestnuts, matted thick
with wild grape-vines, threw a cavernous gloom over it. To pass this bridge was the
severest trial. It was at this identical spot that the unfortunate André was captured, and
under the covert of those chestnuts and vines were the sturdy ♦yeoman concealed who
surprised him. This has ever since been considered a haunted stream, and fearful are
the feelings of the schoolboy who has to pass it alone after dark.
The hair of the affrighted pedagogue rose upon his head with terror. What was to
be done? To turn and fly was now too late; and, besides, what chance was there of
escaping ghost or goblin, if such it was, which could ride upon the wings of the wind?
Summoning up, therefore, a show of courage, he demanded in stammering accents
—“Who are you?” He received no reply. He repeated his demand in a still more
agitated voice. Still there was no answer. Once more he cudgelled the sides of the
inflexible Gunpowder, and, shutting his eyes, broke forth with involuntary fervor into
a psalm tune. Just then the shadowy object of alarm put itself in motion, and with a
scramble and a bound stood at once in the middle of the road. Though the night was
dark and dismal, yet the form of the unknown might now in some degree be
ascertained. He appeared to be a horseman of large dimensions, and mounted on a
black horse of powerful frame. He made no offer of molestation or sociability, but kept
aloof on one side of the road, jogging along on the blind side of old Gunpowder, who
had now got over his fright and waywardness.
Ichabod, who had no relish for this strange midnight companion, and bethought
himself of the adventure of Brom Bones with the Galloping Hessian, now quickened
his steed in hopes of leaving him behind. The stranger, however, quickened his horse
to an equal pace. Ichabod pulled up, and fell into a walk, thinking to lag behind—the
other did the same. His heart began to sink within him; he endeavored to resume his
psalm tune, but his parched tongue clove to the roof of his mouth, and he could not
utter a stave. There was something in the moody and dogged silence of this
pertinacious companion that was mysterious and appalling. It was soon fearfully
accounted for. On mounting a rising ground, which brought the figure of his fellow-
traveler in relief against the sky, gigantic in height, and muffled in a cloak, Ichabod
was horror-struck on perceiving that he was headless!—but his horror was still more
increased on observing that the head, which should have rested on his shoulders, was
carried before him on the pommel of the saddle: his terror rose to desperation; he
rained a shower of kicks and blows upon Gunpowder, hoping by a sudden movement
to give his companion the slip—but the spectre started full jump with him. Away then
they dashed, through thick and thin; stones flying and sparks flashing at every bound.
Ichabod’s flimsy garments fluttered in the air, as he stretched his long lank body away
over his horse’s head, in the eagerness of his flight.
They had now reached the road which turns off to Sleepy Hollow; but
Gunpowder, who seemed possessed with a demon, instead of keeping up it, made an
opposite turn, and plunged headlong down the hill to the left. This road leads through
a sandy hollow, shaded by trees for about a quarter of a mile, where it crosses the
bridge famous in goblin story, and just beyond swells the green knoll on which stands
the whitewashed church.
As yet the panic of the steed had given his unskilful rider an apparent advantage in
the chase; but just as he had got half-way through the hollow the girths of the saddle
gave way, and he felt it slipping from under him. He seized it by the pommel, and
endeavored to hold it firm, but in vain; and he had just time to save himself by
clasping old Gunpowder round the neck, when the saddle fell to the earth, and he
heard it trampled under foot by his pursuer. For a moment the terror of Hans Van
Ripper’s wrath passed across his mind—for it was his Sunday saddle; but this was no
time for petty fears; the goblin was hard on his haunches; and (unskilful rider that he
was!) he had much ado to maintain his seat; sometimes slipping on one side,
sometimes on the other, and sometimes jolted on the high ridge of his horse’s
backbone, with a violence that he verily feared would cleave him asunder.
An opening in the trees now cheered him with the hopes that the church bridge
was at hand. The wavering reflection of a silver star in the bosom of the brook told
him that he was not mistaken. He saw the walls of the church dimly glaring under the
trees beyond. He recollected the place where Brom Bones’ ghostly competitor had
disappeared. “If I can but reach that bridge,” thought Ichabod, “I am safe.” Just then
he heard the black steed panting and blowing close behind him; he even fancied that
he felt his hot breath. Another convulsive kick in the ribs, and old Gunpowder sprang
upon the bridge; he thundered over the resounding planks; he gained the opposite side;
and now Ichabod cast a look behind to see if his pursuer should vanish, according to
rule, in a flash of fire and brimstone. Just then he saw the goblin rising in his stirrups
and in the very act of hurling his head at him. Ichabod endeavored to dodge the
horrible missile, but too late. It encountered his cranium with a tremendous crash—he
was tumbled headlong into the dust, and Gunpowder, the black steed, and the goblin
rider passed by like a whirlwind.
The next morning the old horse was found without his saddle, and with the bridle
under his feet, soberly cropping the grass at his master’s gate. Ichabod did not make
his appearance at breakfast—dinner-hour came, but no Ichabod. The boys assembled
in the schoolhouse, and strolled idly about the banks of the brook; but no
schoolmaster. Hans Van Ripper now began to feel some uneasiness about the fate of
poor Ichabod and his saddle. An inquiry was set on foot, and after diligent
investigation they came upon his traces. In one part of the road leading to the church
was found the saddle trampled in the dirt; the tracks of horses’ hoofs deeply dented in
the road, and evidently at furious speed, were traced to the bridge, beyond which, on
the bank of a broad part of the brook, where the water ran deep and black, was found
the hat of the unfortunate Ichabod, and close beside it a shattered pumpkin.
The brook was searched, but the body of the schoolmaster was not to be
discovered. Hans Van Ripper, as executor of his estate, examined the bundle, which
contained all his worldly effects. They consisted of two shirts and a half; two stocks
for the neck; a pair or two of worsted stockings; an old pair of corduroy smallclothes;
a rusty razor; a book of psalm tunes, full of dog’s ears; and a broken pitch-pipe. As to
the books and furniture of the schoolhouse, they belonged to the community, excepting
Cotton Mather’s History of Witchcraft, a New England Almanac, and a book of
dreams and fortune-telling: in which last was a sheet of foolscap much scribbled and
blotted in several fruitless attempts to make a copy of verses in honor of the heiress of
Van Tassel. These magic books and the poetic scrawl were forthwith consigned to the
flames by Hans Van Ripper; who from that time forward determined to send his
children no more to school, observing that he never knew any good come of this same
reading and writing. Whatever money the schoolmaster possessed, and he had
received his quarter’s pay but a day or two before, he must have had about his person
at the time of his disappearance.
The mysterious event caused much speculation at the church on the following
Sunday. Knots of gazers and gossips were collected in the churchyard, at the bridge,
and at the spot where the hat and pumpkin had been found. The stories of Brouwer, of
Bones, and a whole budget of others, were called to mind; and when they had
diligently considered them all, and compared them with the symptoms of the present
case, they shook their heads, and came to the conclusion that Ichabod had been carried
off by the Galloping Hessian. As he was a bachelor, and in nobody’s debt, nobody
troubled his head any more about him, the school was removed to a different part of
the Hollow, and another pedagogue reigned in his stead.
CHARLES DUDLEY
WARNER.
.
Had he not been a “born writer” the next period of his life
would have made a literary career impossible for him. A winter
in Michigan, ending in dismal failure, two years of frontier life
as a surveyor, and then the pursuit of legal studies, followed by
the practice of law in Chicago seemed to have been hostages to
fortune against the pursuit of fame in the field of pure literature.