






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Various programming concepts including the development of algorithms, declaration and checking of data types, memory management, and exception handling. It includes examples in pascal and discusses topics such as abstract data types, structural equivalence, and garbage collection.
Typology: Exams
1 / 12
This page cannot be seen from the preview
Don't miss anything!







_j_
Final _Exam "_ CMSC 330 Sections 0201, 0202 " -______. —.---" 21 December 1999 Point total: 175
(please print)
The point value for each question is indicated (in parentheses). Focus; do your own work; use your time productively; enjoy the break.
(23) 1. On the Line provided, write the letter corresponding to each statement below that is TRUE. r & Y q_j k j (^) _,"i k 0 o G ^ V_______
a. COBOL, developed as a teaching language, has not been commercially successful. b. ALGOL was developed by professors as an early artificial intelligence language. c._ The semantics of a language describe the sequence of symbols that make up valid programs. d. Program execution is more efficient in interpreted than in compiled languages. e. Integers, floating-point numbers, and enumerated variables are elementary data types. f. Declaring variables enables type checking at compile time for elementary data types. g. Declaring variables enables type checking at compile time for structured data types. h. Logical operators such as AND and OR are frequently implemented on individual bits, not the entire word. i. Integer subranges and enumerated data types facilitate run-time type checking. j. Relational operators can be used on enumerated data types. k. Variations on lists include stacks, queues, trees, and directed graphs.
(9) 2. On the line provided, write the letter corresponding to each statement below that is TRUE.
a. FORTRAN uses dynamic storage management to improve execution speed. b. The ripple effects of a programmer error are reduced if the programmer controls memory management. c. C provides programmers with extensive control over memory management. d. In direct reuse of variable-sized elements of heap storage, best fit is more time efficient than first fit. e. In direct reuse of variable-sized elements of heap storage, first fit provides more effective use of memory than best fit. f. Partial compaction of variable-sized elements of heap storage puts all available memory in one contiguous block. g. Garbage is created by pointers to elements of the free space list. h. Garbage collection is performed in the background while computation continues. i._ Reference counts increase the need for garbage collection.
(6) 3. Given the grammar below, generate the corresponding regular expression.
A -> aA I bB I c Regular Expression B -> bB I cC C -> cC I c -2-
(6) 4. Use the BNF provided to develop a parse tree for a = (a & b) & c
::= a I bl cl d
a = ( a & b )
(Ignore blanks; they are inserted to facilitate drawing the parse tree.)
(12) 13. Provide the output of the following program. The var preceding a formal parameter indicates call by reference. The command writeln prints the output and provides a carriage return. All non-local references are resolved by static scope.
Program alias; var a[1..3] of integer, i: integer; procedure First (var j: integer); var i: integer; begin i:=l; j:=7; a[i]:=15; writeln (i, j) end; procedure Second (var j: integer); begin i:=5; j:=3; a[j]:=17; writeln (i, j) end; begin i:=3; a[ 1 ] :=9; a[ 2 ]:=!!; a[3]:=13; First(a[ 1 ]); writeln (i, a[ 1 ], a[ 2 ], a[ 3 ]); Second(i); writeln (i, a[ 1 ], a[ 2 ], a[ 3 ]); end.
Output MS I
I If
3 /r fl
10
(16) 12. The following code is Pascal-like. All non-local references are resolved using static scope. The command writeln prints the output and provides a carriage return. 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. Provide the output of the program for each execution in the indicated spaces.
Program CallBy var a,b: integer; Procedure One(c, d: integer); begin writeln(a, b, c, d); c := c + d; writeln(a, b, c, d); c := c + d; writeln(a, b, c, d); end; begin a := 2; b:=3; One(a, a + b); writeln(a, b); end.
b G- C "
Q '
c/ '
Jr
D
Call bv name
^ c (16) 7. Use the following Pascal-like declaration for parts a and b.
Var A: array [1 .. 5, 3.. 8, 10. .13] of double precision;
Assume the following: Double precision real numbers take 2 memory locations Storage for array A begins at memory location 3000 A is stored in COLUMN major order
(a). Provide specific numeric values for each of the following for A: / virtual origin ___ff.
lower bound for i ____
upper bound for i _____
multiplier for i ____
lower bound for j _________ _
upper bound for j
multiplier forj
lower bound for k
upper bound for k
multiplier for k
Complete the access formula for A[i, j, k]
1-value (A[i, j, k]) = 3<
Provide the specific numeric value for the following:
l-value(A[3, 7, 11]) = 3/o/________
(b). Provide specific numeric values for each of the followingjor A[*, 6, *]
virtual origin _____^
lower bound for i ______
upper bound for i ______
multiplier for i ______
lower bound for k ______
upper bound for k _______ __________
multiplier for k _____^ _______
Complete the access formula: 1-value (A[i, 6, k]) = •*•
Provide the specific numeric value for l-value(A[3, 6, 11]):
(9) 8. The precedence levels for some Pascal operators are given below, from highest precedence to lowest. All operators at the same precedence level are left associative. The operator **, which is not given in the precedence hierarchy, is right associative. Develop the tree representation for the two expressions below.
Not *, /, div, mod, and +, -, or =, <>, >=, <=, <, >, in
a. (^) a or not b and c and b = c
a ** b ** c ** d
(15) 10. Use the principle of unification and the Prolog facts and rules provided below to give ALL VALID RESPONSES to each query. Indicate if there are NO VALID RESPONSES. Relationships use w, x, y, z; constants use a, b, c,... r; variables use A, B, C, D.
x(a,g) x(b,h) x(d,j) x(g,m) x(i,q) x(j,o) x(a,h) x(b,i) x(d,k) x(g,n) x(i,r) x(k,p) x(a,i) x(c,j) x(e,l) x(g,o) x(j,m) x(l,q) x(b,g) x(c,k) x(f,l) x(h,p) x(j,n) x(l,r)
Rules:
y(A, B) :- x(C, A), x(C, B), A <> B z(A, B) :- x(C, A), x(D,B), y(C, D)
. w(A, B, C) :- y(A, B), y(A, C), B <> C
Queries:
z(A, m) _
w(A, B, m)
w(h, A, B)
(9) 11. 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: # Cla&sC instance VariableNames:'' class VariableNames: '' poolDirectories:'' category: nil!
IClassA methodsFor: 'basic'! one 'This is class A' printNl! two self one!!
!ClassB methodsFor: 'basic'! one 'This is class B' printNl! three self two!!
IClassC methodsFor: 'basic'! two 'This is class C'printNl! three self one!!
Statement
I x lx_ ClassB new.x two! I x lx_ ClassC new.x one! I x lx_ ClassC new.x three! I x Ix ClassB new.x three!
Output
"B
IS
8