Concepts of Programming Languages

(Sean Pound) #1

440 Chapter 9 Subprograms



  1. Write a Perl program that passes by reference a literal to a subprogram,
    which attempts to change the parameter. Given the overall design phi-
    losophy of Perl, explain the results.

  2. Repeat Programming Exercise 3 in C#.

  3. Write a program in some language that has both static and stack-
    dynamic local variables in subprograms. Create six large (at least
    100 *100) matrices in the subprogram—three static and three stack
    dynamic. Fill two of the static matrices and two of the stack-dynamic
    matrices with random numbers in the range of 1 to 100. The code in the
    subprogram must perform a large number of matrix multiplication oper-
    ations on the static matrices and time the process. Then it must repeat
    this with the stack-dynamic matrices. Compare and explain the results.

  4. Write a C# program that includes two methods that are called a large
    number of times. Both methods are passed a large array, one by value
    and one by reference. Compare the times required to call these two
    methods and explain the difference. Be sure to call them a sufficient
    number of times to illustrate a difference in the required time.

  5. Write a program, using the syntax of whatever language you like, that
    produces different behavior depending on whether pass-by-reference or
    pass-by-value-result is used in its parameter passing.

  6. Write a generic Ada function that takes an array of generic elements and
    a scalar of the same type as the array elements. The type of the array ele-
    ments and the scalar is the generic parameter. The subscripts of the array
    are positive integers. The function must search the given array for the
    given scalar and return the subscript of the scalar in the array. If the sca-
    lar is not in the array, the function must return –1. Instantiate the func-
    tion for Integer and Float types and test both.

  7. Write a generic C++ function that takes an array of generic elements and
    a scalar of the same type as the array elements. The type of the array ele-
    ments and the scalar is the generic parameter. The function must search
    the given array for the given scalar and return the subscript of the scalar
    in the array. If the scalar is not in the array, the function must return –1.
    Test the function for int and float types.

  8. Devise a subprogram and calling code in which pass-by-reference and
    pass-by-value-result of one or more parameters produces different
    results.

Free download pdf