< Programming Fundamentals < Functions

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

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

Prerequisites

Learners should already be familiar with functions.

Introduction

Main function
DisplayHello function

Review the flowchart example on the right.

Questions

  • 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

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

  • 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

This article is issued from Wikiversity. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.