Day 12 - Parameters and Return Values
Day 12: Parameters and Return Values
Learning Objectives
- AAP-3.A: For procedure calls: Write statements to call procedures.
- AAP-3.B: Explain how the use of procedural abstraction manages complexity in a program.
- AAP-3.C: Develop procedural abstractions to manage complexity in a program by writing procedures.
Essential Questions
- How do parameters make functions more versatile and reusable?
- How do return values allow functions to provide results to the rest of the program?
Materials Needed
- Presentation slides on parameters and return values
- Programming environment
- Function design worksheet
- Parameter and return value exercises
- Exit ticket templates
Vocabulary
- Parameter
- Argument
- Return value
- Pass
- Function call
- Function signature
- Input
- Output
- Scope
Procedure (50 minutes)
Opening (8 minutes)
-
Review and Connection (3 minutes)
- Review basic function concepts from previous lesson
- Connect to today's focus on making functions more versatile with parameters and return values
-
Warm-up Activity (5 minutes)
- Present a simple function that performs a calculation with fixed values
- Ask students how they might modify it to work with different values
- Introduce the need for parameters and return values
Main Activities (32 minutes)
-
Lecture: Function Parameters and Return Values (12 minutes)
- Define parameters as input variables of a function
- Explain the difference between parameters and arguments:
- Parameters are variables in the function definition
- Arguments are values passed when the function is called
- Demonstrate the syntax for functions with parameters:
- PROCEDURE name(parameter1, parameter2, ...)
- Explain how parameters make functions more versatile and reusable
- Introduce return values:
- Purpose of returning results from functions
- Syntax for returning values: RETURN(expression)
- How return values are used in the calling code
- Assigning return values to variables: result ← functionName(args)
- Discuss the flow of execution with parameters and return values
- Explain how parameters and return values create function interfaces
-
Demo: Passing Arguments and Receiving Results (8 minutes)
- Walk through examples of functions with parameters and return values
- Demonstrate how to pass different arguments to the same function
- Show how return values can be used in expressions or stored in variables
- Illustrate the execution flow with parameter passing and value returning
- Show examples of common function patterns:
- Calculation functions that return results
- Conversion functions
- Validation functions that return Boolean values
- Transformation functions that process input and return modified output
-
Hands-on: Writing Functions with Parameters and Return Values (12 minutes)
- Students work in the programming environment
- Guide students through creating functions with parameters and return values
- Have students implement functions for tasks like:
- Mathematical operations with variable inputs
- String processing functions
- Validation functions that return true/false
- Conversion functions between different units or formats
- Encourage students to test their functions with various arguments
Closing (10 minutes)
-
Activity: Creating a Function Library for Common Operations (5 minutes)
- Students work in small groups to design a set of related functions
- Each group focuses on a specific domain (math, string processing, etc.)
- Groups define function signatures with parameters and return types
- Share and discuss the function libraries
- Highlight how well-designed functions create useful tools
-
Exit Ticket and Preview (5 minutes)
- Students develop functions that take parameters and return values
- Preview that next class will focus on function design and documentation
Assessment
- Formative: Quality of function implementation during hands-on activities
- Exit Ticket: Correctness and usability of functions with parameters and return values
Differentiation
For Advanced Students
- Introduce functions with multiple return paths
- Challenge them to create more complex function interfaces
- Discuss parameter passing mechanisms (value vs. reference)
For Struggling Students
- Provide function templates with parameter placeholders
- Focus on simple functions with clear inputs and outputs
- Use diagrams to illustrate parameter passing and value returning
Homework/Extension
- Complete a worksheet with parameter and return value exercises
- Create a mini-library of useful functions for a specific domain
- Research how functions are documented in professional APIs
Teacher Notes
- Emphasize that parameters and return values are what make functions truly powerful
- Watch for confusion between parameters and arguments
- Make connections to mathematical functions with inputs and outputs
- Consider using physical demonstrations to show parameter passing
- Remind students that well-designed function interfaces improve code usability