AP CSP Data Abstraction and Procedural

Download Report

Transcript AP CSP Data Abstraction and Procedural

AP Computer Science Principles
Data Abstraction and Procedural Abstraction Curriculum Module
What is
Abstraction?
On an index card, write your
name and your definition of
abstraction.
Abstraction
►The
process of simplifying or
condensing large amounts of data into
manageable chunks.
►A concept, an idea, or a general
representation that stands for some
complex collection of individual
instances.
3
Consider this Description
► A tall
object that is stretching to the sky
with rough skin. At the top it has several off
shoots that spread out from the center. On
the ends of the shoots are many small
pieces of green softer skin all of the same
or similar shape. Below the ground similar
offshoots spread through the ground.
►What
4
is this object?
Tree
Two Different Senses of Abstraction
►Data Abstraction
► Data
stored in variables
► Bits are a lower level of abstraction
►Procedural Abstraction
► Hiding
the details (encapsulation) of
a complex task under a name with
parameters.
5
Lesson 1: Number Bases: Binary, Octal, Decimal and Hexadecimal
Think Pair Share
Why do use binary numbers
instead of decimal numbers?
Introducing Binary
to Students
What are some of the ways that
you introduce binary numbers
to your students?
Activity 1
Count the Dots
Counting Dots Activity
►Use
index cards to create the
following 5 cards.
10
Counting Dots Activity
►Each
card represents a place value in
binary.
4
2
11
3
2
2
2
1
2
0
2
Counting Dots Activity
► Just
like the decimal number place values
are 1, 10, 100, 1000… The binary number
place values are 1, 2, 4, 8, 16, …
16
12
8
4
2
1
Counting Dots Activity
► How
would we use this to convert the
binary number 11111 to decimal?
13
16
8
4
2
1
1
1
1
1
1
Counting Dots Activity
► Convert
14
the binary number 01011 to decimal.
16
8
4
2
1
0
1
0
1
1
What is Digital?
15
Activity 3
Using Binary for Text
Using Binary for Text
•Use this subset of the ASCII codes to decode this
message.
•http://www.asciitable.com/
43 53 20 52 4F 43 4B 53 21
17
Decoding
Extensions
Brainstorm ideas for how you
can extend this activity.
Activity 4
Using Binary for Images
What are the differences between these two pictures?
20
Pixels and Color Codes
21
Lesson 2: Procedural Abstraction Using Turtle Primitives
Think Pair Share
How do you take your students
from concrete examples to
abstract formulas that use
variables to do the work?
Activity 2
Drawing a Square
Setting up the Graph
► On
your graph paper identify the point (0, 0) It really
doesn’t matter where you put this, but so we don’t
run out of room, put it some where in the center of
the paper.
► Commands:
► penDown() puts the pencil down at the starting
location
► move() moves 10 units in the direction the turtle is
facing
► turn() turns the turtle 90 degrees clockwise
► penUp() lifts the pen off of the paper.
► Start the turtle at (0,0) facing East.
25
Graphing Turtle Movements
26
penDown()
move()
move()
turn()
move()
move()
turn()
move()
move()
turn()
move()
move()
turn()
penUp()
Turn To Your
Partner
How are we demonstrating the
use of abstraction in the code
we just explored?
Think Pair Share
What would your next step be
in developing abstraction with
your students?
Activity 3
drawSquare50x50()
Modify to Make a 50x50 Square
30
penDown()
move()
move()
turn()
move()
move()
turn()
move()
move()
turn()
move()
move()
turn()
penUp()
Modify to Make a 50x50 Square
penDown()
move()
move()
move()
move()
move()
turn()
move()
move()
move()
move()
move()
turn()
31
move()
move()
move()
move()
move()
turn()
move()
move()
move()
move()
move()
turn()
penUp()
Modify to Make a 50x50 Square
32
drawSquare50x50()
{
penDown()
move()
move()
move()
move()
move()
turn()
move()
move()
move()
move()
move()
turn()
move()
move()
move()
move()
move()
turn()
move()
move()
move()
move()
move()
turn()
penUp()
}
Modify to Make a 50x50 Square
drawSquare50x50()
{
penDown()
move(50)
turn()
move(50)
turn()
move(50)
turn()
move(50)
turn()
penUp()
}
33
Activity 5
Student Practice and
Homework
Modify to Make a 60x60 Square
drawSquare50x50()
{
penDown()
move(50)
turn()
move(50)
turn()
move(50)
turn()
move(50)
turn()
penUp()
}
35
drawSquare60x60()
{
penDown()
move(60)
turn()
move(60)
turn()
move(60)
turn()
move(60)
turn()
penUp()
}
Making a General drawSquare(x)
drawSquare50x50()
{
penDown()
move(50)
turn()
move(50)
turn()
move(50)
turn()
move(50)
turn()
penUp()
}
36
drawSquare60x60()
{
penDown()
move(60)
turn()
move(60)
turn()
move(60)
turn()
move(60)
turn()
penUp()
}
drawSquare(x)
{
penDown()
move(x)
turn()
move(x)
turn()
move(x)
turn()
move(x)
turn()
penUp()
}
Activity 7
Draw Triangle Procedure
Writing drawTriangle(x)
►After
modeling creating
drawSquare(x), have students
try other shapes like
drawTriangle(x)
►Use turn(x) to change the
amount of turn.
38
Think Pair Share
How many degrees should we
turn to make a triangle? Try it.
Turn Amount for Triangle
► Is
there a formula that
we could use to
determine the amount
to turn after drawing
each leg of the
triangle?
► Can we generalize
this formula to work
for all equilateral
polygons?
40
Extension
Students can practice using
parameters to create all sorts of
draw procedures including a
general drawPolygon()
procedure.
Activity 8
makeFace() Procedure
Writing makeFace() Procedure
►Have
students use the
procedure that they have
written to create a picture, such
as a face.
►Some other ideas: flower,
arrow, house.
43
Summative
Assessment
Page 33 of the module.
Includes short answer, multiple
choice and application
questions.