Programming Fundamentals/Functions/Parameters

From Wikiversity
Jump to navigation Jump to search

A parameter is a special kind of variable used in a function to refer to one of the pieces of data provided as input to the function.[1] This activity introduces function parameters. This activity will help you understand how to use function parameters in a program.

Objectives[edit | edit source]

  • Understand function parameters.
  • Understand how function parameters are specified in a program.
  • Single-step through a program to observe function parameters.

Prerequisites[edit | edit source]

Learners should already be familiar with functions.

Introduction[edit | edit source]

Main function
Main function
DisplayHello function
DisplayHello function

Review the flowchart example on the right.

Questions[edit | edit source]

  • What syntax is used to pass parameters to a function?
  • How are parameters defined inside a called function?
  • How are parameters referenced inside a called function?

Activity[edit | edit source]

With a partner, perform the following:

  1. Using a visual programming language, create a program matching the flowchart on the right.
  2. Save the program.
  3. Test the program to verify that it works correctly.
  4. Trade places, so that both partners have an opportunity to "drive" the visual programming environment.
  5. Change the environment to display local variables and step through the program one shape at a time.
  6. Working together, create a list of function parameters that would be used to follow the input-process-output model and convert Fahrenheit temperature to Celsius.

Applications[edit | edit source]

  • Identify specific steps which must be followed when creating a program using function parameters.
  • Discuss your activity experience with your classmates. What surprised you? What have you learned that you can apply to your own school or work environment?

References[edit | edit source]