"Midterm
3" Practice Questions
Use these problems to help
study for the first part of the final exam.
For the second (cumulative) part, refer to previous practice questions.
After
you have given all of the problems a good try, see the answers below.
1)
Four things that
are included in an activation record are: _____________________________,
________________________________
2)
________________________________,
______________________________________
3)
Member functions
in Java use ___________________ binding by default, while member functions in
C++ use ____________________ binding by default.
4)
A(n) _______________________ is a synchronization object
devised by _____________________ that has two operations: P (to gain access)
and V (to give up access).
1)
Pascal does not
support Object-Oriented Programming, but it does support data abstraction through its record
type.
2)
In Smalltalk,
strict variable typing is enforced by the compiler.
3) In order for a C++ destructor defined in a subclass to be called, the destructor in the superclass must be declared to be virtual.
1)
Explain what implementation inheritance and interface
inheritance are, and the advantages and disadvantages of each.
2)
Explain what deadlock and starvation
are, and how each can occur. Be
specific.
3)
For a
language such as Pascal, both static links and dynamic links are
needed in the activation record for a subprogram call. Explain what each of these is and why they
are needed.
Traces
1)
Do
Chapter 10 Problem Set Question 1.
2)
Consider
the Prolog program below:
mine([1,2,3,6,8]).
yours([4,7,2,8,9,3]).
check(Head,
[Head|_]) :- write('Next item: '), write(Head), nl.
check(Item,
[_|T]) :- check(Item, T).
check(_,_).
do_it([],
_).
do_it([H1|T1],
L2) :- check(H1, L2), do_it(T1, L2).
pred1 :-
mine(M), yours(Y), do_it(M,Y).
Give the output produced when the pred1 rule is satisfied, and
explain the general idea of what is happening when it executes. Recall the following about Prolog program
execution:
•
By default the DB is search from top to
bottom.
•
A list is either the empty list, [], or a head
item followed by a tail list, [ H | T ] (where T could
be the empty list).
ANSWERS:
1)
Four things that
are included in an activation record are: _____local variables_________,
____temporaries_________________
2)
____parameters_________________,
______return address__________________
3) Member functions in Java use ___DYNAMIC_________ binding by default, while member functions in C++ use ____STATIC__________ binding by default.
4) A(n) ___SEMAPHORE___________ is a synchronization object devised by ___DIJKSTRA___________ that has two operations: P (to gain access) and V (to give up access).
1)
Pascal does not
support Object-Oriented Programming, but it does support data abstraction through its record
type. False – the record only partially supports data abstraction. It does not allow for encapsulation nor for
data hiding
2)
In Smalltalk,
strict variable typing is enforced by the compiler. False – Smalltalk
variables are all dynamically typed based on the objects assigned to them.
3) In order for a C++ destructor defined in a subclass to be called, the destructor in the superclass must be declared to be virtual. True
1)
Explain what implementation inheritance and interface
inheritance are, and the advantages and disadvantages of each.
Answer:
See Slides 145 and 149 in online notes
2)
Explain what deadlock and starvation
are, and how each can occur. Be
specific.
Answer:
See Slides 165 and 166 in online notes
3)
For a
language such as Pascal, both static links and dynamic links are
needed in the activation record for a subprogram call. Explain what each of these is and why they
are needed.
Answer: Static links are used to find the
textual parent subprogram for a given subprogram call. These are necessary to locate
"locally" global variables for the inner subprogram (i.e. they are
declared in the outer subprogram but accessed in the inner subprogram). Dynamic links are used to locate the
calling subprogram of a given subprogram.
These are necessary so that control (and any return values) can be
passed back to the calling subprogram when the called subprogram terminates.
Traces
1)
Do
Chapter 10 Problem Set Question 1.
Answer (from text):

1)
Consider
the Prolog program below:
mine([1,2,3,6,8]).
yours([4,7,2,8,9,3]).
check(Head,
[Head|_]) :- write('Next item: '), write(Head), nl.
check(Item,
[_|T]) :- check(Item, T).
check(_,_).
do_it([],
_).
do_it([H1|T1],
L2) :- check(H1, L2), do_it(T1, L2).
pred1 :-
mine(M), yours(Y), do_it(M,Y).
Give the output produced when the pred1 rule is satisfied, and
explain the general idea of what is happening when it executes. Recall the following about Prolog program
execution:
•
By default the DB is search from top to
bottom.
•
A list is either the empty list, [], or a
head item followed by a tail list, [ H | T ] (where T
could be the empty list).
Answer:
1
?-
pred1.
Next
item: 2
Next
item: 3
Next
item: 8
Idea:
M is instantiated to the list [1,2,3,6,8] and Y is instantiated to the
list [4,7,2,8,9,3]. The do_it()
predicate then recurses through list M, each time
searching list Y for the current value.
If it is found it prints out the value, otherwise it does nothing. The output values are those that appear in
both lists.