Close
Close full mode
logoMakeCode AP CSP

Parameters

Summary

Materials

Instructional Activities and Classroom Assessments

  1. Functions Review (5 minutes)
  2. Introduce Parameters (20 minutes)
  3. Writing Functions with Parameters (25 minutes)
  4. Extension: Code in JavaScript
  5. Reflection
  6. Homework

Learning Objectives

  • AAP-3.A For procedure calls:
    • a. Write statements to call procedures. 3.B
    • b. Determine the result or effect of a procedure call. 4.B
  • AAP-3.B Explain how the use of procedural abstraction manages complexity in a program. 3.C
  • AAP-3.C Develop procedural abstractions to manage complexity in a program by writing procedures. 3.B

Essential Knowledge

  • AAP-3.A.1 A procedure is a named group of programming instructions that may have parameters and return values.
  • AAP-3.A.2 Procedures are referred to by different names, such as method or function, depending on the programming language.
  • AAP-3.A.3 Parameters are input variables of a procedure. Arguments specify the values of the parameters when a procedure is called.
  • AAP-3.A.4 A procedure call interrupts the sequential execution of statements, causing the program to execute the statements within the procedure before continuing. Once the last statement in the procedure (or a return statement) has executed, flow of control is returned to the point immediately following where the procedure was called.
  • AAP-3.A.5 The exam reference sheet provides procName(arg1, arg2, ...) as a way to call
Text: PROCEDURE procName(parameter1, parameter2, ...)
{
<block of statements>
}
Block:
PROCEDURE procName
block of statements
parameter1, parameter2, ...

which takes zero or more arguments; arg1 is assigned to parameter1, arg2 is assigned to parameter2, and so on.

  • AAP-3.B.1 One common type of abstraction is procedural abstraction, which provides a name for a process and allows a procedure to be used only knowing what it does, not how it does it.
  • AAP-3.B.2 Procedural abstraction allows a solution to a large problem to be based on the solutions of smaller subproblems. This is accomplished by creating procedures to solve each of the subproblems.
  • AAP-3.B.4 A procedural abstraction may extract shared features to generalize functionality instead of duplicating code. This allows or program code reuse, which helps manage complexity.
  • AAP-3.B.5 Using parameters allows procedures to be generalized, enabling the procedures to be reused with a range of input values or arguments.
  • AAP-3.B.6 Using procedural abstraction helps improve code readability.
  • AAP-3.B.7 Using procedural abstraction in a program allows programmers to change the internals of the procedure (to make it faster, more efficient, use less storage, etc.) without needing to notify users of the change as long as what the procedure does is preserved.
  • AAP-3.C.1 The exam reference sheet provides
Text:
PROCEDURE procName(parameter1, parameter2, ...)
{
<block of statements>
}
Block:
PROCEDURE procName
block of statements
parameter1, parameter2, ...

which is used to define a procedure that takes zero or more arguments. The procedure contains block of statements.

Details

1. Functions review (5 minutes)

  • Review definition of functions.
  • Review procedural abstraction.

2. Introduce parameters (20 minutes)

  • Define parameters.
  • Define arguments.
  • Explain how functions have parameters.
  • Demonstrate how the computer calls functions with parameters:
    • Use the draw square example.
    • Use a robot algorithm example.
  • Demonstrate how a function can have multiple parameters.
  • Discuss the instruction and explanation for a procedure.
  • Show students an example of a robot algorithm that has a procedure.
  • Discuss the process to using a procedure in a robot algorithm.
  • Explain how procedures and procedure calls are treated on the Exam Reference Sheet.
  • Explain how display and input are treated on the Exam Reference Sheet.

3. Writing functions with parameters (25 minutes)

4. Reflection

If you run out of time, you may also assign this as individual homework. Students should complete their reflection.

  1. How do parameters allow for more flexible code?
  2. Review the functions you have learned, like splash and say, and identify which ones have parameters.
  3. Where might parameters be used in your previous projects?

5. Homework

  • Task students to complete the extension activities on the Problem Set: Parameters page.
  • Practice sets are written as JavaScript exercises and can be accomplished using block based code. Students can choose whichever code editor they feel most comfortable with to complete the problems. If needed, students can copy the JavaScript snippet from the problem set, paste it into the JavaScript workspace in MakeCode, then switch back to Block. It has been demonstrated that exposing students to both block and text based code simultaneously makes the transition from block to text more successful.
πŸ“˜ Unit 5 - AAP Part 2 β€” Previous
Day 2
Next β€” πŸ“˜ Unit 5 - AAP Part 2
Writing Functions with Parameters