Professional Documents
Culture Documents
TRUE/FALSE
2. All the variables in an array have the same name and data type.
3. If you assume an array’s first subscript is 0, you will always be “off by one” in your array
manipulation.
5. You cannot initialize array elements when you declare the array.
6. In many languages, when you declare an array, a constant that represents the array size is
automatically created for you.
8. When you create parallel arrays, each array must be of the same data type.
9. The smaller the array, the more beneficial it becomes to exit the searching loop as soon as you find
what you’re looking for.
10. As with a while loop, when you use a for loop, you must be careful to stay within array bounds.
MULTIPLE CHOICE
2. All the variables in an array are differentiated with special numbers called ____.
a. scripts c. elements
b. subscripts d. pointers
ANS: B PTS: 1 REF: 144
3. A(n) ____, also called an index, is a number that indicates the position of a particular item within an
array.
a. indicator c. subscript
b. element d. script
ANS: C PTS: 1 REF: 144
5. The number of elements an array will hold is known as the ____ of the array.
a. bounds c. constraints
b. limits d. size
ANS: D PTS: 1 REF: 144
7. Each individual element in an array has a unique ____ indicating how far away it is from the first
element.
a. indicator c. subscript
b. element d. script
ANS: C PTS: 1 REF: 144
10. In most modern programming languages, the highest subscript you should use with an 8-element array
is ____ .
a. 6 c. 8
b. 7 d. 9
ANS: B PTS: 1 REF: 144-145
11. When declaring an array, depending on the syntax rules of the programming language you use, you
place the subscript within parentheses or ____ following the group name.
a. asterisks c. curly brackets
b. slashes d. square brackets
ANS: D PTS: 1 REF: 145
12. Most programming languages use a statement similar to the following to declare a three-element array
and assign values to it: ____
a. {20, 30, 40} = num someVals[3]
b. num someVals[3] = {someVals}
c. num someVals[] = 20, 30, 40
d. num someVals[3] = 20, 30, 40
ANS: D PTS: 1 REF: 145
14. The true benefit of an array lies in your ability to use a(n) ____ as a subscript to the array.
a. variable c. operator
b. table d. field
ANS: A PTS: 1 REF: 150
15. Learning to use arrays correctly can make many programming tasks far more ____ and professional.
a. confusing c. slick
b. efficient d. literal
ANS: B PTS: 1 REF: 154
16. When working with arrays, you can use ____ in two ways: to hold an array’s size and as the array
values.
a. structures c. constants
b. literals d. strings
ANS: C PTS: 1 REF: 154
17. Besides making your code easier to modify, using a ____ makes the code easier to understand.
a. constant c. named declaration
b. named constant d. named variable
ANS: B PTS: 1 REF: 154
18. When you search through a list from one end to the other, you are performing a ____ search.
a. linear c. quick
b. binary d. Google
ANS: A PTS: 1 REF: 157
19. A ____ is a variable that you set to indicate whether some event has occurred.
a. handler c. flag
b. rudder d. bug
ANS: C PTS: 1 REF: 157
21. In ____ arrays, each element in one array is associated with the element in the same relative position in
the other array.
a. parallel c. grouped
b. related d. combined
ANS: A PTS: 1 REF: 158
22. When you use parallel arrays, two or more arrays contain ____ data.
a. connected c. identical
b. equivalent d. related
ANS: D PTS: 1 REF: 159
23. When you use parallel arrays, a ____ relates the arrays.
a. link c. subscript
b. flag d. script
ANS: C PTS: 1 REF: 159
24. The relationship between an item’s number and its price is a(n) ____ relationship.
a. direct c. hidden
b. indirect d. clear
ANS: B PTS: 1 REF: 161
25. Leaving a loop as soon as a match is found improves the program’s ____.
a. indirect relationships c. simplicity
b. logic d. efficiency
ANS: D PTS: 1 REF: 162
26. A ____ search starts looking in the middle of a sorted list, and then determines whether it should
continue higher or lower.
a. linear c. graphic
b. quick d. binary
ANS: D PTS: 1 REF: 163
27. In Java, C++, and C#, the for loop looks like the following:
a. for(dep = 0; dep++; dep < SIZE)
b. for(dep > SIZE; dep = 0; dep++)
c. for(dep = 0; dep < SIZE; dep++)
d. for(dep = SIZE, dep > 0, dep++)
ANS: C PTS: 1 REF: 166
28. An element in an array is 3 bytes long and there are 10 elements in the array. How big is the array?
a. 30 bytes c. 3 bytes
b. 10 bytes d. Not enough information to determine
ANS: A PTS: 1 REF: 164
29. The ____ is a particularly convenient tool when working with arrays because you frequently need to
process every element of an array from beginning to end.
a. binary search c. for loop
b. range check d. parallel array
ANS: C PTS: 1 REF: 165
30. When you have a six element array and use subscript 6, your subscript is said to be out of ____.
a. bounds c. range
b. scope d. array
ANS: A PTS: 1 REF: 165
Case 1
You have just starting working at Quantum Company. As a new programmer, you have been asked to
review and correct various pseudocode.
31. The following pseudocode is not working correctly. How should the for loop be changed?
start
Declarations
num count = 0
num scores[6] = 0,0,0,0,0,0
num SIZE = 6
for count 0 to SIZE step
input entry
scores[count] = entry
endfor
stop
32. The following pseudocode is not working correctly. The code should total the array elements. What
code needs to be changed?
start
Declarations
num count = 0
num total = 0
num scores[6] = 2,4,6,8,10,12
while count < 6
total = total + scores
count = count + 1
endwhile
stop
33. You are working with parallel arrays to detemine the grade a student earns in a class. The student earns
a grade based on the following:
35. The following pseudocode is not working correctly. What kind of error is this?
start
Declarations
num count = 0
num scores[6] = 0,0,0,0,0,0
num SIZE = 6
for count 0 to SIZE step 1
input entry
scores[count] = entry
endfor
stop
a. out of memory c. out of bounds
b. no match was found d. bounded
ANS: C PTS: 1 REF: 165 TOP: Critical Thinking
SHORT ANSWER
1. Write the pseudocode to define a five element array called “scores,” and then allow a user to enter 5
scores and store them in the array using a while loop.
ANS:
start
Declarations
num count = 0
num scores[5] = 0,0,0,0,0
while count < 5
input entry
scores[count] = entry
count = count + 1
endwhile
stop
2. Write the pseudocode to define and initialize a four element array called “evens,” with even numbers
from 2 to 8, and then find the total of the values in the array using a while loop.
ANS:
start
Declarations
num count = 0
num total = 0
num scores[4] = 2,4,6,8
while count < 4
total = total + scores[count]
count = count + 1
endwhile
stop
3. Define and initialize an array that contains the names of the days of the week.
ANS:
string DAYS[7] = "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday"
4. Write the pseudocode to define a six element array called “scores,” and then allow a user to enter 6
scores and store them in the array using a for loop.
ANS:
start
Declarations
num count = 0
num scores[6] = 0,0,0,0,0,0
num SIZE = 6
for count 0 to SIZE - 1 step 1
input entry
scores[count] = entry
endfor
stop
5. Write the pseudocode to define and initialize a five element array called “evens,” with even numbers
from 2 to 10, and then find the total of the values in the array using a for loop.
ANS:
start
Declarations
num count = 0
num evens[5] = 2,4,6,8,10
num SIZE = 5
for count 0 to SIZE - 1 step 1
total = total + evens[count]
count = count + 1
endfor
stop
Among the feudal towns of Japan which can boast of a fine castle
still standing, and of an illustrious lord as its former occupant, there
are few that can rival Hikoné. Picturesquely seated on a wooded hill
close to the shores of Lake Biwa, with the blue waters and almost
equally blue surrounding mountains in full sight, the castle enjoys the
advantages of strength combined with beauty; while the lords of the
castle are descended from a very ancient family, which was awarded
its territory by the great Iyéyasu, the founder of the Tokugawa
Shōgunate, in return for the faithful services of their ancestor,
Naomasa, in bringing the whole land under the Tokugawa rule. They
therefore belonged to the rank of the Fudai Daimio, or Retainer
Barons, from whom alone the Roju, or Senators, and other officers of
the first class could be appointed. Of these lords of Hikoné much the
most distinguished was Naosuké, who signed the treaty with the
United States negotiated in 1857 and 1858. And yet, so strange are
the vicissitudes of history, and so influential the merely incidental
occurrences in human affairs, that only a chance visit of the Mikado
saved this fine feudal castle from the “general ruin of such buildings
which accompanied the mania for all things European and the
contempt of their national antiquities, whereby the Japanese were
actuated during the past two decades of the present régime.” Nor
was it until recent years that Baron Ii Naosuké’s memory has been
rescued from the charge of being a traitor to his country and a
disobedient subject of its Emperor, and elevated to a place of
distinction and reverence, almost amounting to worship, as a clear-
sighted and far-seeing statesman and patriot.
“PICTURESQUELY SEATED ON A WOODED HILL”
However we may regard the unreasonableness of either of these two
extreme views of Naosuké’s character, one thing seems clear. In
respect to the laying of foundations for friendly relations between the
United States and Japan, we owe more to this man than to any other
single Japanese. No one can tell what further delays and resulting
irritation, and even accession of blood-shed, might have taken place
in his time had it not been for his courageous and firm position
toward the difficult problem of admitting foreigners to trade and to
reside within selected treaty-ports of Japan. This position cost him
his life. For a generation, or more, it also cost him what every true
Japanese values far more highly than life; it cost the reputation of
being loyal to his sovereign and faithful to his country’s cause. Yet
not five Americans in a million, it is likely, ever heard the name of
Baron Ii Kamon-no-Kami, who as Tairō, or military dictator, shared
the responsibility and should share the fame of our now celebrated
citizen, then Consul General at Shimoda, Townsend Harris. My
purpose, therefore, is two-fold: I would gladly “have the honour to
introduce” Ii Naosuké to a larger audience of my own countrymen;
and by telling the story of an exceedingly interesting visit to Hikoné, I
would equally gladly introduce to the same audience certain ones of
the great multitude of Japanese who still retain the knightly courtesy,
intelligence and high standards of living—though in their own way—
which characterised the feudal towns of the “Old Japan,” now so
rapidly passing away.
Baron Ii Naosuké, better known in foreign annals as Ii Kamon-no-
Kami, was his father’s fourteenth son. He was born November 30,
1815. The father was the thirteenth feudal lord from that Naomasa
who received his fief from the great Iyéyasu. Since the law of
primogeniture—the only exceptions being cases of insanity or bodily
defect—was enforced throughout the Empire, the early chances that
Naosuké would ever become the head of the family and lord of
Hikoné, seemed small indeed. But according to the usage of the Ii
clan, all the sons except the eldest were either given as adopted
sons to other barons, or were made pensioned retainers of their
older brother. All his brothers, except the eldest, had by adoption
become the lords of their respective clans. But from the age of
seventeen onward, Naosuké was given a modest pension and
placed in a private residence. He thus enjoyed years of opportunity
for training in arms, literature, and reflective study, apart from the
corrupting influences of court life and the misleading temptations to
the exercise of unrestricted authority—both of which are so injurious
to the character of youth. Moreover, he became acquainted with the
common people. That was also true of him, which has been true of
so many of the great men of Japan down to the present time. He
made his friend and counsellor of a man proficient in the military and
literary education of the day. And, indeed, it has been the great
teachers who, more than any other class, through the shaping of
character in their pupils, have influenced mankind to their good. It
was Nakagawa Rokurō who showed to Naosuké, when a young
man, the impossibility of the further exclusion of Japan from foreign
intercourse. It was he also who “influenced the future Tairō to make a
bold departure from the old traditions” of the country.
On the death, without male issue, of his oldest brother, Naosuké was
declared heir-apparent of the Hikoné Baronetcy. And on Christmas
day of 1850 he was publicly authorised by the Shōgunate to assume
the lordly title of Kamon-no-Kami. It is chiefly through the conduct of
the man when, less than a decade later, he came to the position
which was at the same time the most responsible, difficult and
honourable but dangerous of all possible appointments in “Old
Japan,” that the character of Baron Ii must be judged. On the side of
sentiment—and only when approached from this side can one
properly appreciate the typical knightly character of Japanese
feudalism—we may judge his patriotism by this poem from his own
hand: