June 17, 2013

KBP chapter 9

Rickvian Aldi / 02PCT / 1601253441
Assignment By Mr. Tri Djoko Wahjono

Review Questions
1. What are three general characteristics of subprograms ?
- each subprograms has a single entry point
- 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 returns to the caller when the subprogram execution terminates.

2. What does it mean for a subprogram to be active ?
- if it has been called and started execution but the execution is not completed yet.

3. What is given in the header of a subprogram ?
- specifies that the following syntactic unit is a subprogram definition of some particular kind, provides name of the subprogram, optionally specifies a list of parameters
4. What characteristics of Python subprograms sets them apart from those of other languages ?
- function def statements are executable
5. What languages allow a variable number of parameters ?
- C,C++,Perl JavaScript, and Lua
6. What is a Ruby array formal parameter ?
- Substitute of keyword parameter which Ruby does not support
7. What is a parameter profile ? What is a subprogram protocol ?
- Parameter profile contains number, order and types of its formal parameter. Subprogram Protocol is the parameter profile and the return value if it is a function.
8. What are formal parameters ? What are actual parameters ?
- formal parameters are parameters in the subprogram header. Actual parameters are a list of parameters included in subprogram call statements
9. What are the advantages and disadvantages of keyword parameters ?
- The advantage is they can appear in any order in the actual parameter list. The disadvantage is the user must know the names of formal parameters.
10 . What are the differences between a function and a procedure ?
- Functions return values while procedure does not .
- Procedure defines new statements, while function define new user-defined operators.

Problem Set

1 .What are arguments for and against a user program building additional definitions for existing operators, as can be done in Python and C++? Do you think such user-defined operator overloading is good or bad ? Support your answer.
Answer :
-Operator overloading is created to make coding easier by able to add a non number object. This will act like an function overloading, which is represent by a operator symbol. but behind that, operator overloading is user defined, so the use of it can be known by only the programmer who coded the overloading. too much overloading will make ambiguity of the program increasing.

3. Argue in support of the templated functions of C++. How is it different from the templated functions of other languages ?
Answer : 
-Templated function will allow function to recieve many diffrent datatyle, for sake of readibility, templated functions is preferable than creating function overloading.

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 ?
answer :
a. )Passed by value
 list[2] = {3,5}
b. )Passed by reference
 list[2] = {6,10}
c. )Passed by value-result
 list[2] = {6,10}

8.Argue against the Java design of not providing operator overloading.
Answer :
Once again, operator overloading is user defined. This will decrease readibility significantly which is make sense if operator overloading is not provided.