Practice Final Exam - Organization Programming Language | CMSC 330, Exams of Programming Languages

Material Type: Exam; Professor: Sussman; Class: ORGNZTN PROGM LANG; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;

Typology: Exams

Pre 2010

Uploaded on 02/13/2009

koofers-user-ntw
koofers-user-ntw 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC 330 Practice Final Examination
Show all work necessary to justify your answers! There are 7 questions.
1. (15 points) Assuming that static scoping rules are used, what will the following pro-
gram, in C++ syntax, output if parameters are passed by:
(a) value?
(b) value-result?
(c) reference?
#include <iostream.h>
int k = 5;
void f(int i, int j) {
if(i<4)i=i+1;
else i=i-1;
j=j+2;
k=k-1;
}
main() {
intj=3;
f(j, k);
f(k, j);
cout << j << " " << k << '\n';
}
2. (15 points)
Give an unambiguous grammar for the language:
L=
f
w
j
w
2f
0
;
1
g
and
w
contains exactly one occurrence of the substring 10
g
pf3

Partial preview of the text

Download Practice Final Exam - Organization Programming Language | CMSC 330 and more Exams Programming Languages in PDF only on Docsity!

CMSC 330 Practice Final Examination

Show all work necessary to justify your answers! There are 7 questions.

  1. (15 p oints) Assuming that static scoping rules are used, what will the following pro- gram, in C++ syntax, output if parameters are passed by:

(a) value? (b) value-result? (c) reference?

#include <iostream.h> int k = 5;

void f(int i, int j) { if (i < 4) i = i + 1; else i = i - 1; j = j + 2; k = k - 1; }

main() { int j = 3; f(j, k); f(k, j); cout << j << " " << k << '\n'; }

  1. (15 p oints) Give an unambiguous grammar for the language: L = f w j w 2 f 0 ; 1 g and w contains exactly one o ccurrence of the substring 10 g
  1. (15 p oints) You are given an array A whose elements are structures of typ e S.

struct S { char c[2]; float f; double d[2]; int i; } A[30,20,10];

For this problem assume that chars take up one byte, ints and oats take up 4 bytes each and doubles take up 8 bytes, and that the elds in a structure must have their natural alignment.

(a) (5 p oints) Show the layout of variables of typ e S, with the o set of the rst eld in the structure b eing 0. (b) (10 p oints) Assuming that array indices always start at 0 and the start address for array A is 1000, what will b e the address of A[20,5,5], if A is stored in: i. row ma jor order? ii. column ma jor order?

  1. (15 p oints) Variables of typ e set of Z are usually stored as bit vectors, with 1 bit for each element. For example, if Z is the set, [orange, kiwi, blueberry, grapefruit, pear, banana, straw- berry, plum], then a variable of the typ e set of Z would b e represented as an 8-bit vector. The rst bit represents the element orange, the second bit represents kiwi, etc. If a bit is set (1), then the corresp onding element is a memb er of the set. Otherwise the element is not a memb er of the set.

(a) What is the representation for the set A = [banana, kiwi], and the set B = [straw- berry, kiwi, plum, grapefruit]? (b) What machine instruction could b e used to p erform the op eration C = A [ B , and what is the representation for C? (c) What op erations must b e p erformed to test whether the element blueberry is in the set C? Show b oth the set op erations and machine instruction(s) required.