Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the following code segments. procedure Main is X, Y, Z : Integer; procedure

ID: 3666302 • Letter: U

Question

Use the following code segments.

procedure Main is

X, Y, Z : Integer;

procedure Sub1 is

A, Y, Z : Integer;

begin ...

end;

procedure Sub2 is

A, B, Z : Integer;

begin ...

procedure Sub4 is

A, B, W : Integer;

begin ...

end;

end;

procedure Sub3

is A, X, W : Integer;

begin ...

end;

begin ...

end;

1. Q1: Consider the program above. Given the following calling sequences and assuming that dynamic scoping is used, what variables are visible during the execution of the last subprogram activated? Include with each visible variable the name of the unit where it is declared (e.x. Main.X):

a. Main calls Sub1; Sub1 calls Sub2; Sub2 calls Sub4;

b. Main calls Sub1; Sub1 calls Sub3; Sub3 calls Sub2;

Explanation / Answer

a. Main.X, Main.Y, Main.Z, Sub4.A, Sub4B, Sub4W, Sub2.A, Sub2B, Sub2.Z

b. Main.X, Main.Y, Main.Z, Sub2.A, Sub2B, Sub2.Z