 A program is being designed to enable users who are not computer
experts to solve problems using a large file of geographic data: for
example, to list the three longest rivers in Africa or to list the
provinces of France. Of the following, which would be the most
reasonable design for the user interface for such a program?
 Printing out a copy of the file
 Displaying the first screenful of the file, and then displaying
the next screenful each time the user types a space
 Displaying a menu of general topics on the screen and having the
user proceed to lowerlevel menus by typing a single character
 Prompting the user to type an integer code for the data wanted
 Offering the user an optional tutorial that is designed to
increase the user's expertise with computers in general
 Which of the following is NOT likely to be done by a Pascal compiler?
 Checking that parameters passed to procedures are of the correct
type
 Generating machinecode or some other lowlevel code
 Providing a program listing
 Finding all syntax errors
 Finding all infinite loops
 Which of the following statements about using a highlevel language
instead of a machine language is NOT true?
 As a general rule, programs written in a highlevel language are m
ore likely to be executable on machines produced by different
manufacturers.
 Programs written in a highlevel language are generally easier to
read and understand than are programs written in machine language.
 Programs written in a highlevel language generally run faster
than do programs written in machine language.
 Programs written in a highlevel language are generally shorter
than are programs written in machine language.
 Programs written in a highlevel language are generally easier to
debug than are programs written in machine language.
 A procedure is to be written that will check arithmetic expressions to
make sure that the number of left parentheses, NumLeft, equals the
number of right parentheses, NumRight, in such an expression.
Consider the additional variables Sum, Diff, and
Prod used in the statements below.
Sum := NumRight + NumLeft;
Diff := NumRight  NumLeft;
Prod := NumRight * NumLeft;
Knowledge of the value of which variable defined above is sufficient to
be able to decide whether an expression has the same number of right
parentheses as left parentheses?
 NumLeft
 NumRight
 Sum
 Diff
 Prod
 If evaluating BBB has no side effects, under what condition(s)
can the program segment
while BBB do
Block1
be rewritten as
repeat
Block1
until not BBB
without changing the effect of the code?
 Under no conditions
 If executing Block1 does not affect the value of BBB
 If the value of BBB is true just before the segment is
executed
 If the value of BBB is false just before the segment is
executed
 Under all conditions
 Consider the following declarations.
type
IntArrayType = array[1..Many] of integer;
StructureType = record
IntArray : IntArrayType;
Length : integer
end;
function Search(Structure : StructureType; Key : integer) : integer;
{ Precondition: 0 < Structure.Length < Many }
{ }
{ Postcondition: (1) Returns i such that 0 <= i <= Structure.Length. }
{ (2) If positive i is returned, then Structure.IntArray[i] = Key. }
{ (3) If 0 is returned, then Key is not equal to Structure.IntArray[i] }
{ for all i <= Structure.Length. }
var
Index : integer;
begin
Index := 1;
with Structure do
begin
while (IntArray[Index] < Key) and (Index < Length) do
Index := Index + 1;
if IntArray[Index] = Key then
Search := Index
else
Search := 0
end
end;
Which of the following should be added to the precondition of
Search?
 The value of Key appears at least once in
Structure.IntArray.
 The value of Key does not appear twice in
Structure.IntArray.
 Structure.IntArray is sorted smallest to largest.
 Structure.IntArray is sorted largest to smallest.
 Structure.IntArray is unsorted.
 A good reason for not using any var parameters in a
function declaration is that
 var parameters are not permitted in a function
 var parameters take more space than value parameters
 array entries cannot be passed as var parameters
 var parameters in a function allow changes to variables
within the scope of the function call
 var parameters cannot be passed to a local procedure within
a function unless a forward declaration has been made
 Topdown programming is illustrated by which of the following?
 Writing a program in the topdown dialect of Pascal
 Writing a program without using goto's
 Writing the first lines of a program before writing the last lines
 Writing the program in terms of abstract operations and then
refining those abstract operations
 Writing and testing the lowestlevel routines first and then
combining these routines to form appropriate abstract operations
 A list of integers can be stored sequentially in an array. The list can
be maintained in sorted order. Maintaining the list in sorted order in
an array leads to inefficient execution for which of the following
operations?
 Inserting and deleting elements
 Printing the list
 Computing the average of the elements
 I only
 II only
 III only
 I and III only
 I, II, and III
 A usedcar dealer wants to keep an inventory of the cars on a lot that
can hold at most LotSize cars. The model, year, and color need to
be recorded for each car. Assume that the following declarations are
part of the program.
type
Model = (Sedan, Coupe, Liftback, StationWagon);
Year = 1960..1990;
Color = (Red, Blue, Green, White, Brown, Black);
Of the following, which indicates the best data structure for storing the
inventory information?

CarRange = 1..LotSize;
Inventory = record
m : Model;
y : Year;
c : Color;
n : CarRange
end;

Inventory = array[Model, Year, Color] of Boolean;

Inventory = array[Model, Year] of Color;

CarRange = 1..LotSize;
Inventory = record
m : array[Model] of CarRange;
y : array[Year] of CarRange;
c : array[Color] of CarRange
end;

CarRange = 1..LotSize;
Inventory = array[CarRange] of record
m : Model;
y : Year;
c : Color
end;
 An algorithm for searching a large sorted array for a specific entry
x compares every fourth item in the array to x until it
finds one that is larger than or equal to x. Whenever a larger
item is found, the algorithm examines the preceding three entries. If
the array is sorted smallest to largest, which of the following describes
all cases when this algorithm might use fewer comparisons to find
x than would a binary search?
 It will never use fewer comparisons.
 When x is very close to the beginning of the array
 When x is in the middle position of the array
 When x is very close to the end of the array
 It will always use fewer comparisons.
 If the value of f(x, y, z) is always an integer, which of the
following conditions ensures that the loop below terminates?
while f(x, y, z) <> 0 do
<some computation>
 x, y, and z are each increased during each
iteration.
 x, y, and z are each decreased during each
iteration.
 The sum of x, y, and z is decreased during
each iteration.
 The value of f(x, y, z) is decreased during each iteration.
 The value of sqr(f(x, y, z)) is decreased during each
iteration.
 The following program segment is intended to sum A[1] through
A[N].
Sum := 0;
i := 0;
while i <> N do
begin
Sum := Sum + A[i];
i := i + 1
end
In order for this segment to perform as intended, which of the following
modifications, if any, should be made?
 No modification is necessary.
 The segment Sum := 0; i := 0; should be changed to
Sum := A[1]; i := 1;
 The segment while i <> N do should be changed to
while i <= N do
 The segment Sum := Sum + A[i]; should be
changed to Sum := Sum + A[i  1];
 The segment i := i + 1 should be changed
interchanged with Sum := Sum + A[i]
Questions 1415 refer to the following program segment.
const
Size = 10;
type
GridType = array[1..Size, 1..Size] of char;
function YesOrNo(Grid : GridType;
Row,
Colm : integer;
Mark : char) : Boolean;
var
i, Count : integer;
OK : Boolean;
begin {YesOrNo }
Count := 0;
for i := 1 to Size do
if Grid[i, Colm] = Mark then
Count := Count + 1;
OK := (Count = Size);
Count := 0;
for i := 1 to Size do
if Grid[Row, i] = Mark then
Count := Count + 1;
YesOrNo := (OK or (Count = Size))
end; {YesOrNo }
 Which of the following conditions on an array g of type GridType
will by itself guarantee that
YesOrNo(g, 1, 1, '*')
will have the value true when evaluated?
 The element in the first row and first column is '*'.
 All elements in both diagonals are '*'.
 All elements in the first column are '*'.
 II only
 III only
 I and II only
 II and III only
 I, II, and III
 Which of the following best describes what the function YesOrNo
does?
 Counts the occurrences of Mark in Grid and returns
true when the count is less than Size.
 Determines whether there are exactly Size occurrences of
Mark in Grid.
 Determines whether it is true that all entries in row Row
are equal to Mark or all entries in column Colm are
equal to Mark.
 Determines whether it is true that all entries in row Row
and all entries in column Colm are equal to Mark.
 Counts the occurrences of Mark on the main diagonal of
Grid and returns true when Count equals
Size.
 Consider the following two program segments.
{repeat loop} {for loop}
i := First for i := First to Last do
repeat for j := 1 to i do
writeln('repeat loop output'); writeln('for loop output')
i := i + 1
until i > Last
If First = 1 and Last = 1, how many times will the output
lines "repeat loop output" and "for loop output", respectively, be
written?
 2, 1
 2, 6
 3, 1
 3, 3
 3, 6
Questions 1718 refer to the following function.
function WhatIsIt(x, n : integer) : integer;
begin
if n = 1 then
WhatIsIt := x
else
WhatIsIt := x * WhatIsIt(x, n  1)
end;
 What value is returned by WhatIsIt(4, 4)?
 8
 16
 24
 64
 256
 Which of the following is a necessary and sufficient condition for the
function WhatIsIt to return a value if it is assumed that the
values of n and x are small in magnitude?
 n > 0
 n ≥ 0
 n > 0 and x > 0
 x ≤ n and n > 0
 n ≤ x and n > 0
 All of the entries in the array a with position indices
Spot to Last, inclusive, (Spot ≤ Last) are
to be shifted one position so that a new entry can be inserted at
a[Spot]. Which of the following statements correctly shifts the
entries? (Assume that Last is less than the maximum index for
a.)

for i := Spot to Last do
a[i + 1] := a[i]

for i := Last downto Spot do
a[i + 1] := a[i]

for i := Spot + 1 to Last do
a[i + 1] := a[i]

for i := Last  1 downto Spot do
a[i + 1] := a[i]

for i := Spot to Last  1 do
a[i + 1] := a[i]

procedure Wow(n : integer);
begin
if n > 1 then Wow(n div 2);
write(n, ' ')
end;
The procedure call Wow(16) will yield as output which of the
following sequences of numbers?
 10 8 6 4 2
 16 8 4 2 1
 1 2 4 8 16
 32 16 8 4 2
 2 4 8 16 32
 Merging two sorted lists to yield a single sorted list requires which of
the following?
 That the two lists be external files
 That recursive techniques be used
 That at least one list be stored in memory
 That nonrecursive techniques be used
 None of the above
 Consider the following declarations.
const
MaxNum = 5;
type
String = array[1..MaxNum] of char;
procedure GetLine(var Line : String);
var
i : integer;
ch : char;
begin
for i := 1 to MaxNum do
Line[i] := '+';
i := 0;
while not eoln and (i < MaxNum) do
begin
read(ch);
if ch in ['?', '#'] then
case ch of
'?' : i := 0;
'#' : if i > 0 then
i := i  1
end
else
begin
i := i + 1;
Line[i] := ch
end
end { while }
end;
Assume an input line of
A?B#C?DEF#GH##I
Upon completion of procedure GetLine, Line is returned to
the calling routine as
 EFGHI
 DEI++
 DEGH+
 DIGH+
 DEIH+
 If b is a Boolean variable, then the statement b := (b =
false) has what effect?
 It causes a compiletime error message.
 It causes a runtime error message.
 It causes b to have value false regardless of its
value just before the statement was executed.
 It always changes the value of b.
 It changes the value of b if and only if b had value
true just before the statement was executed.
 Graphics commands, such as a command to position the cursor at an
arbitrary position, are not part of standard Pascal. One good reason for
this exclusion is that
 Pascal was designed for an educational environment in which
drawing pictures is to be discouraged
 Pascal programs execute too slowly to produce worthwhile graphics
output
 The data structures needed to support good graphics cannot be
implemented in Pascal
 The graphics capabilities of output devices vary widely
 such commands can easily be defined in terms of the output
procedures of standard Pascal
 During one iteration of the outer for loop of the program segment
below, how many times is the body of the inner for loop
executed?
for i := 1 to n  1 do
for j := n downto i + 1 do
if A]j  1] > A[j] then
begin
Temp := A[j  1];
A[j  1] := A[j];
A[j] := Temp
end;
 i + 1
 n  i + 1
 i  n + 1
 n(i  1)
 n  i
 A questionnaire with 20 questions was given to 1,000 people between the
ages of 20 and 49. The answer choices for each question were: agree, no
opinion, and disagree. The designers of the questionnaire want to store
in a computer the number of people who gave each answer to each
question, broken down by the age group of the respondent. The age groups
are 2029, 3039, and 4049. The declarations below have been made.
const
NumQues = 20;
NumPeople = 1000;
type
AnsType = (Agree, NoOpinion, Disagree, NoReply);
AgeGroup = (Twenties, Thirties, Forties);
Which of the following is an appropriate type declaration for storing the
information?

SurveyType = array[1..NumQues, AnsType, AgeGroup] of integer;

SurveyType = array[1..NumPeople, AnsType, 20..49] of Boolean;

SurveyType = array[1..NumPeople, 1..NumQues] of AnsType;

SurveyType = array[1..NumQues] of AnsType;
AgeType = array[AgeGroup] of integer;

TotalType = array[1..NumPeople, AgeGroup] of integer;
AnswerType = array[1..NumQues] of AnsType;
Questions 2728 are based on the following block structure. (Assume
there are no variable declarations other than the ones explicitly
shown.)
procedure p1;
var
a, b : real;
procedure p2;
var
b : integer;
c : char;
procedure p3;
var
a : real;
c : integer;
begin { p3 };
...
end { p3 };
begin {p2}
...
end {p2};
procedure p4;
var
b : real;
begin { p4 }
...
end {p4 };
begin { p1 }
...
end { p1 };
 The variable a declared in procedure p1 can be used in the
statement part of
 p1 only
 p1 and p2 only
 p1 and p4 only
 p1, p2, and p4 only
 p1, p2, p3, and p4
 Which of the following is true of the variable b if it is used in
the body of p3?
 It is a variable of type real.
 It is a variable of type integer.
 It is an illegal reference because b is not declared in
p3.
 Its value would depend on whether or not p4 has been
called.
 None of the above
 Suppose Pascal did not support sets. Given a base set (universe)
consisting of 8 known elements, subsets of that universe could be
represented using all of the following EXCEPT
 An integer variable ranging between 0 and 2^{8}  1,
inclusive
 A variable of an enumerated type with 8 elements
 an array of 8 elements
 8 Boolean variables
 8 integer variables
Questions 3031 are based on the following program.
program Sample(output);
var
a, b : integer;
procedure Proc(x, y, z : integer);
begin
y := y + 1;
z := z + x
end;
begin
a := 2;
b := 3;
Proc(a + b, a, a);
write(a)
end.
 What is printed by the program above?
 2
 3
 5
 7
 8
 If the procedure heading
procedure Proc(x, y, z : integer);
were changed to
procedure Proc(x : integer; var y, z : integer);
what would be printed by the program?
 2
 3
 5
 7
 8
 Consider the following function.
function Mult(x, y : integer) : integer;
{ Precondition : x > 0 }
{ }
{ Postcondition : Returns x * y }
begin
if x = 1 then
<statement 1>
else
<statement 2>
end;
Which of the following statement pairs properly completes the
function?
<Statement 1> <Statement 2>

Mult := x * y <none>

Mult := y Mult := Mult(x  1, y + 1)

Mult := y Mult := Mult(x  1, y + y)

Mult := y Mult := Mult(x  1, y) + y

Mult := y Mult := Mult(x  1, y) * y
 Suppose that Grid is an nbyn array of integers,
and a procedure is to be used to reflect the entries across the main
diagonal. (The main diagonal goes from the upper left corner to the
lower right corner.) For example, if n = 3 and the array
contained
1 2 3
4 5 6
7 8 9
the procedure would change it to
1 4 7
2 5 8
3 6 9
If Swap interchanges the values of its parameters, which of the
following w9ill NOT have the desired effect?

for Row := 1 to n do
for Colm := 1 to n do
Swap(Grid[Row, Colm], Grid[Colm, Row])

for Row := 1 to n do
for Colm := 1 to Row do
Swap(Grid[Row, Colm], Grid[Colm, Row])

for Row := 2 to n do
for Colm := 1 to Row  1 do
Swap(Grid[Row, Colm], Grid[Colm, Row])

for Row := 1 to n  1 do
for Colm := Row + 1 to n do
Swap(Grid[Row, Colm], Grid[Colm, Row])

for Row := 1 to n  1 do
for Colm := Row to n do
Swap(Grid[Row, Colm], Grid[Colm, Row])
 Consider two ways to code a procedure that repeatedly prints a
character.

procedure PrintChars(ch : char; HowManyTimes : integer);
var i : integer;
begin
for i := 1 to HowManyTimes do
write(ch)
end;

procedure PrintChars(ch : char; var HowManyTimes : integer);
var i : integer;
begin
for i := 1 to HowManyTimes do
write(ch)
end;
Which of the following is true concerning the choice of headers?
 Header I is preferable because it uses less memory space.
 Header I is preferable because it permits a call with an
expression as an actual parameter.
 Header II is preferable because it avoids copying the value of
HowManyTimes.
 Both headers are equally appropriate since the procedure bodies
are the same.
 Both headers are equally appropriate since HowManyTimes is
not changed in either procedure body.
 In a certain programming language, the syntax of the
"multipleassignment statement" is
x1, x2 := Expr1, Expr2
where x1 and x2 are integer variables and Expr1 and
Expr2 are integer expressions whose evaluations have no side
effect. This statement is executed as follows.
 The values of Expr1 and Expr2 are computed first.
 Then the value of Expr1 is assigned to x1 and the
value of Expr2 is assigned to x2.
The new statement is correctly implemented in Pascal by which of the
following?

x1 := Expr1;
x2 := Expr2
 MultiAssig1(x1, x2, Expr1, Expr2) where MultAssig1 is
declared as:
procedure MultAssig1(v1, v2, e1, e2 : integer);
begin
v1 := e1;
v2 := e2
end;
 MultiAssig2(x1, x2, Expr1, Expr2) where MultAssig2 is
declared as:
procedure MultAssig2(var v1, v2 : integer; e1, e2 : integer);
begin
v1 := e1;
v2 := e2
end;
 I only
 II only
 III only
 I and III
 II and III