Uploaded by J R

FinalExam

advertisement
CSC-4330/6330, Programming Language Concepts (Fall 2023)
Final Exam (Comprehensive)
In-Class and Open Book
November 30, 2023
Name:
Panther #:
Put the answers on these sheets. Show how you derived at your answer (this is required for full credit and
helpful for partial credit). You can collect 100 points in total for this exam. Each question carries 10 points.
1. Consider the following pseudocode:
void swap (int a, int b) { int temp; temp = a; a = b; b = t; }
void main() { int value = 1, list[5] = {1, 3, 5, 7, 9};
swap(value, list[value]);
print value, list[0], list[1], list[2], list[3], list[4];
}
What does it print using call-by-value, call-by-value-result, call-by-reference, call-by-name, and
call-by-need parameter passing techniques? Justify your answer.
Page 1 of 5
2. Consider the following pseudocode:
x : integer := 0;
procedure A(n:integer)
x := n;
procedure B()
x : integer := 5;
A(1);
write_integer(x);
begin /* main */
B();
write_integer(x);
end
What does it print if language uses static scoping? Dynamic scoping? Justify your answer.
3. Consider the following pseudocode:
x : integer := 1;
procedure one
write_integer(x);
procedure two(P : procedure)
x : integer := 2;
P(); x := 3;
one();
begin /* main */
two(one);
end
What does it print if language uses static scoping? Dynamic scoping with deep binding? Dynamic
scoping with shallow binding? Justify your answer.
Page 2 of 5
4. Consider the following Prolog program:
box(yellow, hotweels). box(yellow, puzzle). box(red, dress). box(red, shoes). box(blue, book).
addressed_to(yellow, alex). addressed_to(blue, alex). addressed_to(red, becky).
addressed_to(green, chris).
gift(Person, Gift) :- addressed_to(Color, Person), box(Color, Gift).
no_gift(Person) :- addressed_to(Color, Person), not box(Color, Gift).
(a) What is the first value of X returned by the goal gift(alex, X)?
(b) Which person does not receive a gift? That is, what is the value of X returned by the goal
no_gift(X)?
5. Write a recursive LISP function for implementation of set difference operation:
e.g. Call to (set_diff
‘(1
2
3)
‘(2
4)) shall return (1
3)
6. Assume that main is the outermost procedure defined in the program. The procedures B and E
are defined inside main procedure; whereas, procedure C is defined inside procedure E and
procedure D is defined inside C. Assume the calling sequence is main, B, E, C, D. Show the runtime stack with static and dynamic chains for each procedure called.
Page 3 of 5
7. Construct a precedence graph and write a concurrent program using fork/join constructs for the
following statements, S0 through S10:
S0: x = y = 2;
S1: z = x + 1;
S2: a = y + 2; S3: b = a + z;
S4: c = b + 5; S5: d = b – 3;
S6: p = a + 7; S7: e = c + d; S8: q = p;
S9: r = p + 10; S10: s = q + r + e;
8. Consider a base class called ‘foo’ containing two data members a and b, of type integer, and two
virtual member functions f and g. Also, consider a derived class called ‘bar’ which is inherited from
class ‘foo’, containing one integer data member y, one virtual member function h and an
overridden method g. Suppose we create an object of class ‘bar’, say B. Show memory
representation of object B along with necessary arrangements made for virtual functions.
Page 4 of 5
9. Suppose a 2-dimensional array is declared as: int a[15][20];
Let us assume the following:
• 32-bit machine architecture is used
• Row-major order layout for arrays is used
• Base Address of the array is 1000 (in decimal).
What will be the location of a[7][16] (in decimal)?
10. A language with string manipulation facilities uses the following operations
head(s): first character of a string
tail(s): all but the first character of a string
concat(s1,s2): s1s2
for the string acbc, what will be the output of
concat(head(tail(tail(s))), head(s))? Justify your answer.
Page 5 of 5
Download