Section 7.7

Modular Arithmetic

Learning Goals


AAP-2.C: Evaluate expressions that use arithmetic operators. 

AAP-2.C.1: Arithmetic operators are part of most programming languages and include addition, subtraction, multiplication, division, and modulus operators. 

AAP-2.C.2: The exam reference sheet provides a MOD b, which evaluates to the remainder when a is divided by b. Assume that a is an integer greater than or equal to 0 and b is an integer greater than 0. For example, 17 MOD 5 evaluates to 2. 

AAP-2.C.3: The exam reference sheet provides the arithmetic operators +, -, *, /, and MOD. 

AAP-2.C.4: The order of operations used in mathematics applies when evaluating expressions. The MOD operator has the same precedence as the * and / operators. 


Objectives and Description

The objective of this lesson is to both introduce students to the modulo operator while also reinforcing previously taught concepts (specifically conditionals and loops). Students will be creating a looped drum beat, something they are already familiar with, and modifying the code to add a drum fill to a specific measure.

Activities

Activity 7.7.1 (Budget 50 minutes)

Activity 7.7.2 (Budget 45 minutes)

Resources