Thursday, June 27, 2013

Concepts of Programming Languages Chapter 9


Concepts of Programming Languages Chapter 9


Name            : Erland
NIM              : 1601218035
Lecturer       : Tri Djoko Wahjono, Ir., M.Sc. (D0206)
Assignment  : Concept of programming languages Chapter 9

Review Questions


       1.  What are the 3 general characteristics of subprograms?
             Answer : 
– each subprograms has a single entry end points – the calling program unit is suspended during the execution of the called subprogram,which implies that there is only one subprogram in execution at any given time – control always return to the caller when the subprogram execution terminates
       2. What does it mean for a subprogram to be active?
            Answer : 
A subprogram is said to be active after having been called, it has begun execution but has not yet completed that execution
       3. What is given in the header of a subprogram?
             Answer :
The header is given a special words type
       6. What is ruby array formal parameter?
             Answer :
Ruby array formal parameter is the single parameter which followed by the hash item which preceded by an asterik. Ruby allows a variable number of parameters in a way similar to C# because ruby arrays can store different types.
       7. What is a parameter profile? What is subprogram protocol?
             Answer : 
Parameter profile of a subprogram contains the number, order, and types of its formsl parameter. A protocol of subprogam is ite parameter profile plus, if it is a function, its return type。
       8What are formal parameters? What are actual parameter?
           Answer : 
The parameters in the subprogram header are called formal parameters. Subprogram call statements must include the name of the subprogram and a list of parameters to be bound to the formal parameters of the subprogram. These parameters are called actual parameters.

        9. What are the advantages and disadvantages of the keyword parameter?
             Answer:
The advantage of keyword parameters is that they can appear in any order in the actual parameter list. The disadvantage to keyword parameters is that the user of the subprogram must know the names of formal parameters.?


        10.  What are the differences between a function and a procedure?
                Answer : 
a function returns value but procedures do not. Function are structurally resemble procedures but are semantically modeled on mathematical parameter.

       11. What are the design issues of a subprogram?
             Answer :
– are local variable statically or dynamically allocated? – can subprogram definitions appear in other subprogram definition? – what parameter-passing method or methods are used? – can subprogram overload? – can subprogram be generic? – if a language allow nested subprogram, are closures supported?


         12. What are the advantages and disadvantages of dynamic local variable?
             Answer : 
advantage: – they are bound to storage whdn the subprogram begins execution and are unbound from storage when that execution terminates – flexible – the storage for local variables in an active subprogram can be shared with the local variable in all inactive subprogram.

Disadvantage: – the cost of time required to allocate, initialize, and deallocate such variables for each call to the subprogram. – the access to stack-dynamically local variable must be indirect. – subprogram cannot be history sensitive.
         13. What are the advantages and disadvantages of static local variable?
                Answer : 
Advantage :
-more efficient
-they require no run-time overhead for allocation and deallocation.   
Disadvantages :
- inability to support recursion.
-storage cannot be shared with the local variables of other inactive subprograms.
14. What languages allow subprogram definition to be nested?
       Answer :
Algol 60, Algol 68, Pascal, Ada