Prof. Tak Auyeung
You, as an individual, are expected to do your own work. This means you cannot seek, receive or otherwise acquire any assistance except clarifications from the professor during an examination. Any communication involving the contents of the subject matter or the examination is considered cheating. Do not initiate or accept such communication, or the result of your examination is automatically voided.
New rules, read this! As of 2003.09.22, I no longer deduct points for wrong answers. Each correct answer is worth one point, each wrong answer is worth zero point, and each unanswered question is also worth zero point. This means you should guess and leave no question unanswered.
As a result, I also need to adjust the letter grade assignment break points. For your individual examinuation, ``A'' means at least 94%, ``B'' means at least 74%, ``C'' means at least 54%, ``D'' means at least 34% and ``F'' means below 34%. The break points for the final grade are now 26.83%, 48.5%, 70.17% and 91.83% as minimums for ``D'', ``C'', ``B'' and ``A'', respectively.
Please note that this change does not affect your letter grade at all, it is just a number game to make some people feel better about guessing.
Make sure you write down you name on the upper right corner first, otherwise I cannot give points to anonymous students!
The baseline is XX, there are XX questions.
f('00231')?
function f(s : string) : integer;
var
i : integer;
x : integer;
begin
x := 0;
for i := 1 to length(s) do
if (s[i] >= '0') and (s[i] <= '3') then
x := x * 4 + (ord(s[i]) - ord('0'));
f := x
end;
type
n = record w, x : integer end;
var
a : array [0..4] of n;
i,j : integer;
begin
for i := 0 to 4 do
read(a[i].w, a[i].x);
j := 0;
for i := 0 to 4 do
begin
write(a[j].w,' ');
j := a[j].x
end
end.
Given that the input to this program is as follows:
23 4 102 2 34 3 32 0 299 1
What is the output of this program?
f('this is insane!','s'), given that
the function is defined as follows?
function f(s : string; c : char) : integer;
var i, x : integer;
begin
x := 0;
for i := 1 to length(s) do
if s[i] = c then
x := x + 1;
f := x
end;
p('vashTheStempede'), given that
procedure p is defined as follows?
procedure p(s : string);
var i : integer;
begin
for i := 1 to 6 do
if i <= length(s) then
write(s[i])
else
write('*')
end;
vashTh
vashTh*********
*********empede
vashTheStempede
123456
type
t1 =
record
a : array [0..9] of integer;
b : string [20];
c : integer
end;
t2 =
record
x : array [0..29] of t1;
y : array [0..29] of integer;
z : integer
end;
var
v1 : t2;
Which of the following expression is not valid? Some expressions may not return a built-in type, but they are still syntactically correct as parameters.
v1.z
v1.y[2]
v1.x[v1.y[v1.z]]].b[2]
v1.a[length(v1.b)]
v1.x
type
t1 = array [0..9] of integer;
t2 = array [0..2] of t1;
var
v1 : t2;
procedure p1(var x : array of integer);
begin
(* ... whatever p1 does *)
end;
Which of the following invocation does not generate a compile-time error?
p1(v1[2])
p1(v1)
p1(v1[2][1])
p1(v1.t2[0])
p1(v1[1][2][1])
rewrite
append
assign
close
reset
____ so that the
program compiles without any errors?
(* ... a whole bunch of user defined types *) var outfile : text; x : ____; begin (* ... to initialize infile for writing *) write(outfile, x); (* .. other operations) end.
boolean
integer
real
var
i : integer;
procedure p1(x : integer);
begin
i := x;
while (i > 0) do
begin
write('*');
i := i - 1
end;
writeln
end;
procedure p2(x : integer);
begin
i := 0;
while (i < x) do
begin
p1(i+1);
i := i + 1
end
end;
begin
p2(3)
end.
***
* ** ***
*** ** *
**
*
x has
a value of 27?
if x < 20 then
writeln('do')
else if x < 25 then
writeln('re')
else if x < 30 then
writeln('me')
else if x < 35 then
writeln('fa')
else
writeln('so')
do
re
me
do re
me fa so
var
bad_global : boolean;
function f : boolean;
begin
f := not bad_global
end;
begin
if f = bad_global then
writeln('weird')
else
writeln('strange')
end.
f = bad_global should have
been bad_global = f
weird
strange
bad_global
function f1 : integer;
begin
f1 := 4
end;
function f2(x : integer; y : integer) : integer;
begin
f2 := f1 * x + y
end;
begin
writeln(f2(f2(f1,2),f1+2))
end.
while (x < y) and (y < z) and (z < x) do
begin
writeln('*');
x := x + 1;
y := y - 1
end;