Monday, June 24, 2013

Concepts of Programming Languages 10th Edition : Chapter 9

Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT

Review Questions

1. What are the three general characteristics of subprograms?
   => - Each subprogram has a single entry point.
      - The calling program unit is suspended during the execution of the called subprogram, which implies that there is only subprogram in execution at any given time.
      - Control always returns to the caller when the subprogram execution terminates.

8. What are formal parameters? What are actual parameters?
   => Formal parameters are the parameters in the subprogram header, whereas actual parameters are a list of parameters to be bound to the formal parameters of the subprogram.

10. What are the differences between a function and a procedure?
    => Functions structurally resemble procedures bu are semantically modeled on mathematical function.

11. What are the design issues for subprograms?
    => The design issues for subprograms are:
- Are local variables statically or dynamically allocated?
- Can subprogram definitions appear in other subprogram definitions?
- What parameter-passing method or methods are used?

24. What is an overloaded subprogram?
    => An overloaded subprogram is one that has the same name as another subprogram in the same referencing environment.

25. What is ad hoc binding?
    => The environment of the call statement that passed the subprogram as an actual parameter is called ad hoc binding.

26. What is multicast delegate?
    => Multicast delegate is the all of the methods stored in a delegate instance are calles in the order in which they were placed in the instance.

32. What exactly is a delegate?
    => Delegate is a power and flexibility of method pointers which is increased by making them objects.

34. What is a closure?
    => Closure is a nested subprogram to be called from anywhere in a program.



Problem Set

3. Argue in support of the templated functions of C++. How is it different from the templated functions of other languages?
   => It is different as C++ differentiates function based on overloading. It is not practical to make multiple function overloading in regard to writability and readability. Instead, creating a template allows a function to receive any datatype as long as the variation is based on the formal parameter definition.

5. Consider the following program written in C syntax:
void swap(int a, int b) {
int temp;
temp = a;
a = b;
b = temp;
}

void main() {
int value =1, list[5]= {2,4,6,8,10};
swap (value,list[0]);
swap(list[0],list[1]);
swap(value,list[value]);
}
   for each of the following parameter-passing methods, what are all of the values of the variables value, and list after each of the three calls to swap?
a. Passed by value
b. Passed by reference
c. Passed by value-result

   => a. Passed by Value
          -value =1 , list[5] = {2,4,6,8,10}
         b. Passed by reference
         -value =6, list[5] ={4,1,2,8,10}
         c. Passed by value-result
         -value =6, list[5] ={4,1,2,8,10}

7. Consider the following program written in C syntax:
void fun(int first, int second){
first+=first;
second+=second;
}

void main(){
int list[2] ={3,5};
fun(list[0],list[1]);
}
   for each of the following parameter-passing methods, what are the values of the list array after execution?
a. Passed by value
b. Passed by reference
c. Passed by value-result

   =>   a. 3, 5
  b. 6, 10
  c. 6, 10

15. How is the problem of passing multidimensional arrays handled by Ada?

    => Ada compilers are able to determine the defined size of the dimensions of all arrays that are used as parameters at the time subprograms are compiled.

No comments:

Post a Comment