Pada post
Review Questions
1. What is a Ruby array formal parameter?
Ruby supports a complicated but highly flexible actual parameter configuration. The initial parameters are expressions, whose value objects are passed to the corresponding formal parameters. The initial parameters can befollowing by a list of key => value pairs, which are placed in an anonymous hash and a reference to that hash is passed to the next formal parameter. These are used as a substitute for keyword parameters, which Ruby does not support. The hash item can be followed by a single parameter preceded by an asterisk. This parameter is called the array formal parameter.
Ruby supports a complicated but highly flexible actual parameter configuration. The initial parameters are expressions, whose value objects are passed to the corresponding formal parameters. The initial parameters can be
2. What is a parameter profile? What is a subprogram protocol?
Parameter profile is the number, order, and types of its formal parameters. Subprogram protocol is its parameter profile plus, if it is a function, its return type. In languages in which subprograms have types, those types are defined by the subprogram’s protocol.
Parameter profile is the number, order, and types of its formal parameters. Subprogram protocol is its parameter profile plus, if it is a function, its return type. In languages in which subprograms have types, those types are defined by the subprogram’s protocol.
3. What are formal parameters? What are actual parameters?
The common solution to the nesting problem is to use alternating means of forming a compound
4.What are the advantages and disadvantages of the keyword parameter?
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.
5. What are the differences between a function and a procedure?
Functions return values and procedures do not.
Problem Sets
procedure .
6. Present one argument against providing both static and dynamic local variables in subprograms!
it’s resulting a less time efficient result.
7. Cons ider the following program written in C syntax: void fun (int first, int second) {
first += first;
second += second;
}
void main() {
int list[2] = {1, 3};
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
list={1,3}
b. Passed by reference
list={2,4}
c. Passed by value-result
list={2,4}
8. Argue against the C design of providing only function subprograms!
It’s okay, as a void function can serve as a first += first;
second += second;
}
void main() {
int list[2] = {1, 3};
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
list={1,3}
b. Passed by reference
list={2,4}
c. Passed by value-result
list={2,4}
8. Argue against the C design of providing only function subprograms!
9. From a textbook on Fortran, learn the syntax and semantics of statement functions. Justify their existence in Fortran.
The Fortran 1966 standard provided a reference syntax and semantics, but vendors continued to provide incompatible extensions. These standards have improved portability.
10. Study the methods of user-defined operator overloading in C++ and Ada, and write a report comparing the two using our criteria for evaluating languages.
One of the nice features of C++ is that you can give special meanings to operators, when they are used with user-defined classes. This is called operator overloadin g. You can implement C++ operator overloads by providing special member-functions on your classes that follow a particular naming convention. For example, to overload the + operator for your class, you would provide a member-function named operator+ on your class. Meanwhile for Ada, since much of the power of the language comes from its extensibility, and since proper use of that extensibility requires that we make as little distinction as possible between predefined and user-defined types, it is natural that Ada also permits new operations to be defined, by declaring new overloading of the operator symbols.
One of the nice features of C++ is that you can give special meanings to operators, when they are used with user-defined classes. This is called operator overloadi
No comments:
Post a Comment