Midterm 2
Midterm 2
Midterm 2
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
CSc 330 F01 1<br />
<strong>Midterm</strong> 2<br />
NAME: STUDENT NO:<br />
1. (25%) For each of the following type construction methods, give a simple type declaration<br />
in Ada that illustrates the concept:<br />
(a) (6%) subset<br />
(b) (6%) product<br />
(c) (7%) sum<br />
(d) (6%) function<br />
2. (25%) Given the following language for specifying types:<br />
::= Int | Bool | | -> |<br />
x | array of
CSc 330 F01 2<br />
What are the most general types of h, f, a, l and k? Explain.<br />
procedure h ( f : __ ; a : __ ; l : __ ; k : __ ) is<br />
begin<br />
for i in a’range do<br />
k[i] := k[i] + f( a[i], l[i] );<br />
end;<br />
end;<br />
3. (25%)<br />
(a) (15%) Given two abstract data types DQueue (double-ended queues) and Queue<br />
(single-ended queues), how are they related by subtyping and subclassing? Explain.
CSc 330 F01 3<br />
(b) (10%) Discuss the difference between strong and weak substitutibility.<br />
4. (25%) Reduce the following lambda expression into normal form. Show all your steps.<br />
( (λf.λx.f(fx)) (λf.λx.f(fx)) ) x y