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?
while BBB do
Block1
be rewritten as
repeat
Block1
until not BBB
without changing the effect of the code?
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?
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;
while f(x, y, z) <> 0 do
<some computation>
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?
Questions 14-15 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 }
YesOrNo(g, 1, 1, '*')will have the value true when evaluated?
{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?
Questions 17-18 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;
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?
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##IUpon completion of procedure GetLine, Line is returned to the calling routine as
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;
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 27-28 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 };
Questions 30-31 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.
procedure Proc(x, y, z : integer);were changed to
procedure Proc(x : integer; var y, z : integer);what would be printed by the program?
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
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])
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;
x1, x2 := Expr1, Expr2where 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.
x1 := Expr1; x2 := Expr2
procedure MultAssig1(v1, v2, e1, e2 : integer);
begin
v1 := e1;
v2 := e2
end;
procedure MultAssig2(var v1, v2 : integer; e1, e2 : integer);
begin
v1 := e1;
v2 := e2
end;
The contents of this web page come from The 1988 Advanced Placement Examinations in Computer Science and Their Grading. The following copyright notice appears in that booklet and applies to the content of this page:
Copyright ©1989 by College Entrance Examination Board. All rights reserved.
College Board, Advanced Placement Program, and the acorn logo are registered trademarks of the College Entrance Examination Board.
Permission is hereby granted to any nonprofit organization or institution to reproduce this booklet in limited quantities for its own use, but not for sale, provided that the copyright notices be retained in all reproduced copies exactly as they appear in this booklet. This permission does not apply to any third-party copyrighted material that may be in this booklet.