CSCI 431 Fall 2000:  EXAM 2 Review                

Example Questions:

Consider the following block structured language.

1.       Procedure A
2.       { int a = 0
3.        
4.          Procedure C
5.          {        Procedure D
6.                {  print a;
7.                }
8.          Call D
9.          }
10.      Procedure B
11.      {  char a = 'b';
12.      
13.      Call C;
14.      }
15.      Call B;
}

What is printed when A calls B calls C calls D?

    1. 0 for either static or dynamic scoping
    2. 0 if static scoping, 'b' if dynamic scoping
    3. 'b' if static scoping, 0 if dynamic scoping
    4. 'b' if static scoping, 'b' if dynamic scoping
    5. None of the above.

 

A template function is a function in which

1.      the type of key parameters and local variables is not known until run time.

2.      the type of key parameters and local variables changes dynamically.

3.      the function is compiled without knowing what type will be used.

4.      All of the above

5.      None of the above

 

In a statically scoped language, when a static link exists from the activation record for procedure A to the the activation record for procedure B, this means

    1. A is nested directly within B
    2. B is nested directly within A
    3. A is nested directly or indirectly within B
    4. B called A
    5. none of the above

 

In a call to a function doit() in which B is the actual parameter, to pass B by name, B is evaluated:
(a) in the called environment (b) in the calling environment (c) at the point of call (d) a single time.

 

What is the difference between a tuple and a list in ML?

 

C is said to support only one parameter passing mechanism, what is it?  Are there exceptions to this rule?

 

What is a Display vector, and what is the max number of memory accesses needed to retrieve and non-local variable when a Display vector is used?

 

What information is stored in an activation record, list specific items.

 

True or False, when static scoping is used, activation records must contain an environment table listing the names and values of all local variables.

 

What is the "lifetime" of a variable. What is the "scope" of a variable. Give examples of when they are different?

 

In general, statically declared variables are stored in the _________, and dynamically declared variables are stored in the __________.

 

Name 2 languages that allow some form of "unification"?

 

True or False, Prolog is a functional programming language.

 

The following are Smalltalk messages. In each case, identify the object receiving the message.

 

How does C++ support encapsulation?

 

How does Ada support encapsulation?

 

Identify the programming language used in each of the statements below (each statement may be written in a different programming language):

 

Consider the following program in a language that allows for nested scope:

1.       procedure main 
2.         integer I; 
3.         integer A[0:4]; 
4.         for I=0 to 4 do A[I] = I; 
5.         I=1; 
6.         P(I,A[I]); 
7.         write(I,A[I]); 
8.        
9.         procedure P(integer A; integer B); 
10.       integer T; 
11.       A=A+1; 
12.       T=B+1; 
13.       I=I+1; 
14.       B=A+T; 
15.       write(A,B); 
16.     end P; 
17.   end main; 
 
    1. Assuming Call by Reference:
      1. What is printed for A?
      2. What is printed for B?
      3. What is printed for I?
      4. What is printed for A[I]?
    2. Assuming Call by Value­Result:
      1. What is printed for A?
      2. What is printed for B?
      3. What is printed for I?
      4. What is printed for A[I]?
    3. Assuming Call by Value:
      1. What is printed for A?
      2. What is printed for B?
      3. What is printed for I?
      4. What is printed for A[I]?
    4. Assuming Call by Name:
      1. What is printed for A?
      2. What is printed for B?
      3. What is printed for I?
      4. What is printed for A[I]?

 

For the program above, assume the following addresses:

5.      Location of the instruction in the operating system which calls the main program is 400.

6.      Location of the call to P in procedure main is 600.

7.      Data storage for program begins at 900.

8.      Activation record for main begins at location 1000.

9.      Activation record for P begins at 1100.

Fill in the following values:

10.   Static link in P

11.   Dynamic link in P

 

Give the (a) Postfix and (b) Prefix forms of the C ­language expression 8 + 4/2 - 5

 

Consider the C++ program:

 
#include <stream.h> 
class top {
   public: top() {a=1;}; 
   void newfcn() {local();}; 
   protected: int a; 
   virtual void local() {cout<<a<<endl;};
}; 
class bottom: public top {
   public: bottom() {a=2;}; 
   protected: void local() {cout<<a<<endl;};
}; 
main() {
   top x; 
   bottom y; 
                            x.newfcn(); 
   y.newfcn();
}

1.       What is printed for x.newfcn?

2.       What is printed for y.newfcn?

 

In the program above, what happens if virtual were deleted in the above definition?

3.       What is printed for x.newfcn?

4.       What is printed for y.newfcn?

 

Define the term “Abstract Data Type” (ADT).

 

Name three features of Object Orientated (OO) languages.

 

True or False, an OO language may support 2 kinds of methods in a class: class methods and instance methods.

 

Name 3 problems associated with using infix notation to write expressions.

 

Contrast the implementation of iteration statements in 2 languages.

 

Define the term “Prime Programs”.

 

True or false, is it possible to write any program using only if and while sequence control structures.

 

Mark which of the following sentences are true and which are false.

Function overloading can be resolved at compile time in C++.

Virtual functions can be resolved at compile time in C++.

The following function is legal in ML.

                        Fun add(x,y) = x+y

Pascal, C++, and Ada support encapsulation.

 

Consider the following Prolog database.

fun(X) :-

                        red(X),

                        car(X).

fun(X) :-

                        blue(X),

                        bike(X).

            red(apple_1).

                 red(car_27).

            bike(my_bike).

                 bike(honda_81).

            car(desoto_48).

                 car(edsel_57).

blue(flower_3).

                 blue(honda_81).

 

Suppose the following query is made:

fun(What).

Describes the steps made by the Prolog system in answering the query.  Be specific.  Mention specific instances of unification and backtracking.