AAP-2.A: Students will express an algorithm that uses sequencing without using a programming language.
AAP-2.B: Students will represent a step-by-step algorithmic process using sequential code statements.
AAP-3.A: Students will use abstraction to manage complexity in a program.
AAP-3.A: Students will determine the result of code segments.
AAP-2.G: Students will express an algorithm that uses selection without using a programming language.
AAP-3.B: Students will explain how the use of procedural abstraction manages complexity in a program.
AAP-2.A.1: An algorithm is a finite set of instructions that accomplish a specific task.
AAP-2.A.2: Beyond visual and textual programming languages, algorithms can be expressed in a variety of ways, such as natural language, diagrams, and pseudocode.
AAP-2.A.3: Algorithms executed by programs are implemented using programming languages.
AAP-2.A.4: Every algorithm can be constructed using combinations of sequencing, selection, and iteration.
AAP-2.B.1: Sequencing is the application of each step of an algorithm in the order in which the code statements are given.
AAP-2.B.2: A code statement is a part of program code that expresses an action to be carried out.
AAP-2.B.3: An expression can consist of a value, a variable, an operator, or a procedure call that returns a value.
AAP-2.B.4: Expressions are evaluated to produce a single value.
AAP-2.B.5: The evaluation of expressions follows a set order of operations defined by the programming language.
AAP-2.B.6: Sequential statements execute in the order they appear in the code segment.
AAP-2.B.7: Clarity and readability are important considerations when expressing an algorithm in a programming language.
AAP-2.G.1: Selection determines which parts of an algorithm are executed based on a condition being true or false.
AAP-2.M.1: Algorithms can be created from an idea, by combining existing algorithms, or by modifying existing algorithms.
AAP-2.M.2: Knowledge of existing algorithms can help in constructing new ones. Some existing algorithms include:
● determining the maximum or minimum value of two or more numbers
● computing the sum or average of two or more numbers
● identifying if an integer is or is not evenly divisible by another integer
● determining a robot’s path through a maze
AAP-2.M.3: Using existing correct algorithms as building blocks for constructing another algorithm has benefits such as reducing development time, reducing testing, and simplifying the identification of errors.
AAP-3.A: For procedure calls:
a. Write statements to call procedures.
b. Determine the result or effect of a procedure call.
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.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.3: The subdivision of a computer program into separate subprograms is called modularity.
AAP-3.B.4: A procedural abstraction may extract shared features to generalize functionality instead of duplicating code. This allows for 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.
The objective of this lesson is to both introduce students to procedural abstraction, a way to generalize procedures in a way that can handle multiple different inputs (within some specified parameters). These procedures can be used throughout our code to apply them to different situations or produce different results
Activity 5.9.1 (Budget 20 minutes)
Begin by engaging students with a think-pair-share activity where they are tasked with outlining a mundane step-by-step process from their daily lives.
For example, brushing your teeth is something everyone knows how to do when you mention it, but it is actually a process with a lot of steps:
Grab toothbrush
Wet the toothbrush
Apply toothpaste
Wet the toothbrush
Brush front of teeth
Brush back of teeth
Brush top of teeth
Repeat steps 5-7 as necessary for 2+ minutes
Scrub tongue
Rinse out mouth with water
As students share their processes with the class, make a note to them of how many steps each one is
Additionally, if students share a process that may need more steps or details to be accurate, ask the class what is missing.
After a few examples, engage the students in a discussion about how this might apply to computer science and coding
When we brush our teeth every day, do we need each and every step detailed to us or do we know all the steps just by thinking about "brushing teeth"
Similarly, in a script, if there is a set of actions we want executed multiple times, it is often simpler and more efficient to detail that set of actions as a procedure and call upon that procedure as needed rather than pasting the individual steps multiple times throughout the code.
This is the basis for custom functions and procedures in coding.
4. Any time after you have introduced slide 6, you can begin a discussion about selection. Use this example, Imagine you’re trying to decide what to wear for the day. You look outside and see that it’s raining. You have two options: wear a raincoat or wear a regular jacket. You decide to wear a raincoat because it will keep you dry in the rain. In this scenario, you have used selection to make a decision based on a condition (the weather). Selection is a fundamental concept in programming, but it’s also something we use in our everyday lives. We make decisions based on certain conditions all the time, whether we realize it or not.
Have students pair up and share an algorithm that uses selection without using a programming language.
Activity 5.9.2 (Budget 30 minutes)
Teacher will use their example script from lesson 5.8 to walk students through how to modify existing sections of code to work within the scope of a user-defined function.
Teacher should highlight the importance of switching out original code that indicates specific values with a information from the user-defined function
Example: replacing the values in the “measure” parameter of fitMedia(), makeBeat(), etc with a value that the user inputs into the function
Activity 5.9.3 (Budget 60 minutes)
Students will receive an example script that contains code for a song that must be reformatted using user-defined functions
Take special care when determining what parameters/arguments the user-defined functions will take in, and how these are used in the subsequent code.
There should not be any hard-coded measure inputs for fitMedia() or makeBeat()
The end result should be two user-defined functions that contain the original code that students identify as being either part of section A or B
These new user-defined functions will be called at the end of the script to construct a song with ABAB form.
Sections should cleanly transition and repeat
Activity 5.9.4 (Bonus)
Students will restructure their script from lesson 5.8 (after creating a new copy) by placing the existing code into a user-defined function for a section A, then creating a new section B to create a song with ABAB form (verse-chorus-verse-chorus)
Students should integrate loops with makeBeat to display understanding of code that has two layers of abstraction (custom function parameters and loop variables)