Programming Fundamentals/Functions/Parameters
Appearance
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]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:
- Using a visual programming language, create a program matching the flowchart on the right.
- Save the program.
- Test the program to verify that it works correctly.
- Trade places, so that both partners have an opportunity to "drive" the visual programming environment.
- Change the environment to display local variables and step through the program one shape at a time.
- 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?