Exam Review: CMSC 330 - Notation, Data Types, and Memory Management - Prof. David G. Prest, Exams of Programming Languages

A final exam review for cmsc 330, covering topics such as notation, data types, and memory management. It includes questions on prefix and postfix notation, precedence rules, coercion, subranges, relational operators, boolean variables, structured data objects, abstract data types, coroutines, and memory management concepts like compaction, static and dynamic memory allocation, and garbage collection.

Typology: Exams

Pre 2010

Uploaded on 05/14/2008

koofers-user-0t7
koofers-user-0t7 🇺🇸

10 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Final
Exam
CMSC
330
Sections
0201,
0202
DfcxblteiSTo/viU
S^^tooiS
15
December
1998
Point
total:
175
f
S
(__ »
\
f
NAME;_______________
(please
print)
The
point
value
for
each
question
is
indicated
(in
parentheses).
Do
your
own
work;
use
your
time
wisely;
enjoy
semester
break.
(15)
1.
On
the
line
provided,
write
the
letter
corresponding
to
each
statement
below
that
is
TRUE.
A
_
.
~
_____ft
%
&
rf___________
-
a.
Of
the
three
notations
for
arithmetic
expressions
(i.e.,
infix,
postfix, and prefix),
the
one
with
the
greatest
potential
for
ambiguity
is
infix.
b.
One
advantage
to
prefix
and
postfix
notation
is
that
parentheses
are
not
necessary,
c.
Precedence
rules
determine whether
expressions
are
to
be
evaluated
right-to-left
or
left-to-right.
d.
Using
prefix
notation
eliminates
problems
caused
by
side
effects.
e.
The
use
of
simultaneous
substitutions
to
multiple
expressions
to
find
a
consistent
set
of
values
to
satisfy
all
of
the expressions
is
known
as
backtracking,
f.
Primitive data
types
are
built
into
programming
languages;
the
set
of
primitive
data
types
is
essentially
the
same
for
all
common
programming
languages,
g.
A
coercion-j^
converts
a
data
object
from
one
type
to
another;
it
is
implemented
by
the
programmer.
-
h.
The
advantages
of
subranges
include
smaller
storage
requirements,
i.
The
disadvantages
of
subranges
include
restrictions
on
type
checking,
j.
Relational
operators
do
not
work
with
enumerated
data
types,
k.
Boolean
variables
may be
assigned
one
of
three
values:
true,
false,
and
unknown.
1.
Structured
data
objects
are
limited
to
homogeneous
components.
-m.
An
advantage
of
using
sequential
storage
for
structured
data
objects
is
that
it
enables
random
selection
of
a
component
by
calculation
of
its
memory
location.
n.
Abstract
data
types
do
not
include
the
operations
for
the
data
objects.
o.
Methods
are
inherited
operations;
if
a
method
does
not
exist
for
an
object,
the
method
of
a
child
of
the object
is
used
if
it
exists.
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Exam Review: CMSC 330 - Notation, Data Types, and Memory Management - Prof. David G. Prest and more Exams Programming Languages in PDF only on Docsity!

Final Exam CMSC 330 Sections 0201, 0202 DfcxblteiSTo/viU S^^tooiS 15 December 1998 f S (__ » \ f Point total: 175 NAME;_______________ (please print)

The point value for each question is indicated (in parentheses). Do your own work; use your time wisely; enjoy semester break.

(15) 1. On the line provided, write the letter corresponding to each statement below that is TRUE. A _. _~ _____ft % & rf____________

- a. Of the three notations for arithmetic expressions (i.e., infix, postfix, and prefix), the one with the greatest potential for ambiguity is infix. b. One advantage to prefix and postfix notation is that parentheses are not necessary, c. Precedence rules determine whether expressions are to be evaluated right-to-left or left-to-right. d. Using prefix notation eliminates problems caused by side effects. e. The use of simultaneous substitutions to multiple expressions to find a consistent set of values to satisfy all of the expressions is known as backtracking, f. Primitive data types are built into programming languages; the set of primitive data types is essentially the same for all common programming languages, g. A coercion-j^ converts a data object from one type to another; it is implemented by the programmer.

  • h. The advantages of subranges include smaller storage requirements, i. The disadvantages of subranges include restrictions on type checking, j. Relational operators do not work with enumerated data types, k. Boolean variables may be assigned one of three values: true, false, and unknown.
  1. Structured data objects are limited to homogeneous components. -m. An advantage of using sequential storage for structured data objects is that it enables random selection of a component by calculation of its memory location. n. Abstract data types do not include the operations for the data objects. o. Methods are inherited operations; if a method does not exist for an object, the method of a child of the object is used if it exists.

(20) 2. On the line provided, write the letter corresponding to each statement below that

is TRUE. 5-T

a. A variation in subprogram control frequently used for error handling is coroutines. b. Exception handlers can not be explicitly invoked by the programmer. ^. An assertion is a type of exception that states a relationship that must hold during program execution. /d. Propagation of an exception is along the dynamic chain. e. The advantage of coroutines is that when control returns to the coroutine it returns to the first statement of the coroutine. f. The variation on program control that is based on a real or simulated time scale is called a timing pattern. g. A synchronization approach commonly used for hardware devices is message passing. ,-h. Mutual exclusion is a principle that prohibits multiple tasks from accessing the same data object simultaneously. i. When critical regions are used to implement mutual exclusion, multiple tasks must be in the critical region at the same time. ^-j. When the rendezvous is used to communicate among concurrent tasks, multiple tasks must be in the rendezvous at the same time. sk. The global referencing environment is a subset of the nonlocal referencing environment. A. Compaction of memory is sometimes necessary to generate contiguous blocks of memory. m. Static memory allocation is necessary to enable recursion and dynamic data structures. In stack-based storage management, storage is freed in reverse order of allocation (i.e., LIFO). o. In heap management, storage is freed in reverse order of allocation (i.e., LIFO). p. Two problems of memory management are garbage and dangling participles. Some languages (e.g., C) permit the programmer to directly control some aspects of dynamic memory management. Some languages (e.g., C) permit the programmer to directly control some aspects of static memory management. During garbage collection, other processing is suspended. Two approaches to direct reuse of memory are first fit and best fit; first fit is more time efficient.

(6) 5. The 32-bit IEEE floating point standard is as follows:

A sign bit (0 is positive) 8-bit exponent in excess 127 notation (i.e., subtract 127 from the value in these 8 bits to get the exponent) 23-bit mantissa with an implicit binary point on the left and an implicit 1 to the left of the binary point

(a). Convert the following to a decimal value

^

decimal value = - / B ^ ^

(b). Convert the following decimal value to the 32-bit IEEE floating point standard

C' ^^ decimal value = 3.

C? -^..

(10) 6. Calculate the numeric value of each of the following. (Reminder: / is integer division, i.e., divide and truncate)

Postfix

Prefix

+-7^

Q * + 14 2_ I 4 11

/to ~O

(6) 7. Indicate whether the following statements would be valid or invalid if the language used name equivalence and if the language used structural equivalence for data types.

type A: array [1 ..4] of character; B: array [1..4] of character; var a, b: A; c: B; d: array [1..4] of character; procedure One (a: A); procedure Two (d: character);

name structural quivalence equivalence

a:=b _J____ ______

a:= c ^jNwiH'O »//>/,)T> ,-\ \

One (a) _j

One (c) VKW/^'P \l frL\Q

One (d) __L

Two (a[2j) _yfri-iP

Two (d) i£ij/jl£J

\j j

(b). Fill in the relevant sections of the following memory map for the descriptor of

X[*,l]. Assume that the descriptor begins at location 3000.

NAME VALUE NAME VALUE

,^

^ 3002

Acess formula: 1-value (X[i,l]) =

T- 1- (12) 9. Assume that the two-stage mark-sweep algorithm for garbage collection is used for this LISP example. A stack and heap are indicated for six points in the computation of the function combine. Indicate how garbage collection would proceed during execution of combine. Each word consists of two parts; the first part can either be an element of data or a pointer, the second part is a pointer. Shaded words indicate words that are not available as free space. Mark words by outlining them. (In LISP, the cons function concatenates two lists).

User-defined function: (defun combine (x) (cons '(q r s) x )) ^ \y^ -'^ ,^ ,^ __^ - "^< Function call: (combine '(a b)). )y- J

1."

stack heap

Prior to call

Call (^) Mark Post sweep combine= '(q r s a b)

Post return

(14) 10. Use the Smalltalk subclass definitions and methods for each subclass to provide the indicated output.

Object subclass: # ClassA instance VariableNames:'' class VariableNames:'' poolDirectories:'' category: nil!

ClassA subclass: # ClassB instance VariableNames:'' class VariableNames:'' poolDirectories:'' category: nil!

ClassB subclass: # ClassC instance VariableNames:'' class VariableNames:'' poolDirectories:'' category: nil!

ICIassA methodsFor: 'basic'! picklt 'pick classA' printN.1! peellt self picklt!! steam It 'steam ClassA' printN!

SCIassB methodsFor: 'basic'! picklt 'pickclassB' printNl! steam It self peel It!!

SCIassC methodsFor: 'basic'! steam It self peel It!!

Statement

| x |x_ ClassA new.x picklt!

| x |x_ ClassA new.x peellt! | x |x_ ClassB new.x peellt! | x |x_ ClassB new.x steamlt! | x |x_ ClassC new.x picklt!

| x |x_ ClassC new.x peellt! | x |x_ ClassC new.x steamlt!

Output

a Us,/)

^

/M

(15) 12. The following code is Pascal-like. Execute the program 4 times, each time assuming the parameters are passed using one of the following methods: call by name, call by reference, call by value, and call by value-result.

Program parameter var i: integer; A: array [1 ..3] of integer; Prod (j, k: integer);

AV

print ("i = ", i, "j = ", j, "k = ", k); i := 4; J:=J-2; C1-' print ("i = ", i, "j = ", j, "k = ", k); end;

begin for i:= 1 to 3 do A[i] := i + 1; for i:= 1 to 3 do print ("A[", i,"] = ", A[i]); i := 2; Proci (i, A[i]); print ("i = ", i); for i:= 1 to 3 do print ("A[", i,"] =", A[i]); end.

Give the output for each method:

J

6

Call by name Call by reference Call by value Call by value- result

r r

(12) 13. Give the output for the following program. The var preceding a parameter indicates pass by reference. The command writein prints the output and provides a carriage return.

program Main; var i, j: integer; /" procedure Prod (var i: integer; function F (K : integer): integer); var h: integer; begin h:=1; writein ("i =", i. "j =", j, "h =", h, "in Prod"); h := F(i); writein ("i =", i, "j =", j, "h =", h, "in Prod"); end;

procedure Proc2; varj: integer; function G (varj: integer):integer; begin j:=2; G:=i+j; writein ("i =", i, "j =", j, "in G"); end; begin j:=3; writein ("i =", i, "j =", j, "in ProcZ); Prod G, G); writein ("i =", i, "j =", j, "in Proc2"); end;

begin i:=4; j:=5; Proc2; writein ("i =", i, "j =", j, "in Main"); end.

OUTPUT

  • </* "b.

L -

J

/

11

(10) 15. The psuedo code for two Ada tasks is provided. Task A reads data from an input device into a buffer. Task B processes the data in the buffer. Following the tasks is a set of conditions. Indicate the statement number of both tasks that would be active for each condition.

task A; task B; begin begin A1 -input first data set loop loop B1 wait (StartB); A2 signal (StartB); B2 - process data set A3 wait (StartA); B3 signal (StartA); A4 - input next data set endloop; endloop; end task B; end A;

Condition task A task B

A is reading in the first data set »,, -g /

B is processing the first data set n J A is reading in the third data set &

B has completed processing the fourth data set