Free Pascal Exam Questions
Free Pascal Exam Questions
Sample of the PDF document
1) Given the procedure with header
and pre and post conditions below:
procedure
PrintUpToNum(number: integer);
{ Pre-condition:
number is a positive integer
Post-condition: Will print one line
with the numbers 1 2 3 ... number
separated by a space, followed by a new
line, so the
cursor begins at the beginning of the next
line after
the function call is made.
}
Write a procedure Print_Triangle that
takes in a positive integer n, and
prints a triangle, like so by making
procedure calls to PrintUpToNum.
1 2 3 4 ... n
1 2 3 4
n-1
.
.
.
1
So, the procedure call Print_Triangle(3),
would output:
1 2 3
1 2
1
procedure
Print_Triangle(num_lines: integer);
var
begin
end;
2)
(20 pts) Fill in the output of the following program in the chart provided on the
next page:
program
Chipmunks;
procedure
Alvin(var a: integer; b: integer; var c: integer);
begin
if (a>b) then
a := 2*b
else
b := 2*a;
c := a + b;
writeln(‘In Alvin ‘,a,’ ‘,b,’ ‘,c);
end;
function Simon(a, b, c: integer): integer;
begin
a := b + c;
c := 2*c -
7;
writeln(‘In Simon ‘,a,’ ‘,b,’ ‘,c);
Simon := a+b;
end;
procedure Theodore(var a,b,c: integer);
begin
a := Simon(c,b,a);
b:= 2*c – a;
c:= 7 + 3*c;
writeln(‘In Theodore ‘,a,’ ‘,b,’ ‘,c);
end;
var x, y, z: integer;
begin
x := 1;
y := 4;
z := 5;
Alvin(x,y,z);
writeln(‘In Main ‘,x,’ ‘,y,’ ‘,z);
Theodore(z,y,x);
writeln(‘In Main ‘,x,’ ‘,y,’ ‘,z);
end.
Free Pascal Exam Questions
0 commentaires: