[Skip Navigation] [CSUSB] / [CNS] / [CSE] / [R J Botting] /[CS320 Course Materials] [Text Version] lab/10.html Tue May 17 08:27:35 PDT 2011
Labs: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]


    CSci320 Laboratory 10 Functions in C++

      1 Recursion and activation records

      Download, compile and run [ 11fibo.cpp ] and trace the activation records as it executes. This is not your father's Fibbonaci function!

      Hint: you can ask for different sequences of Fibonaci numbers by changing the arguments when you call the compiled program. If you output the compiled program into 11fibo for example you can

       		11fibo 12 14
      for example.

      By the way here [ fibo.py ] is a translation into Python (without the tracing and counting).

      2 Parameter passing

      Download, compile and test [ 11flipper.cpp ] which use pass by reference.

      Recode it using pass by value of a pointer. In other words, you may not put & in the header of the function. You must use '*' and '&' as prefix operators in expressions. When the program is changed it still does the same thing.

      Link the fixed and the original code to your web page.

      4 Call by Name in C++

      Note. Call by name is alive and well in C++, if you have time look at [ name.cpp ] for an example of Jensen's device from Algol 60.


      Prepare a simple page with links to your lab work today explaining what you have learned in lab today about C++ functions. Link this page into your index/home/cs320 page.

    . . . . . . . . . ( end of section CSci320 Laboratory 10 Functions in C++) <<Contents | End>>

    Check the Preparation for next class

    [ ../11.html ]