ap computer science principles data abstraction and procedural abstraction curriculum module

44
AP Computer Science Principles Data Abstraction and Procedural Abstraction Curriculum Module

Upload: barrie-smith

Post on 12-Jan-2016

227 views

Category:

Documents


1 download

TRANSCRIPT

AP Computer Science Principles

AP Computer Science PrinciplesData Abstraction and Procedural Abstraction Curriculum Module These materials can be found in the CS Principles Teacher community.

1What is Abstraction?On an index card, write your name and your definition of abstraction.Teachers will write their own definition of abstraction. They will practice the Think-Pair-Share strategy by introducing themselves to someone next to them and providing them with their definition of abstraction. At the end of the activity, ask teachers to modify their definition as they feel necessary. That throughout the workshop they will have time to modify their definition based on what they are learning. 2The 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.

Abstraction#Provide this definition that is provided in the module.

3A 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 is this object? Consider this Description

Tree

#Have the participants close their eyes and read the description. Have them write what they think the object is on the back of their index card. Ask them to turn to their partners and tell the other person what the object is. Did they all get Tree? Tell them that our ability to provide a name for an object is our brains way of creating an abstraction. This way we can all use the word tree and everyone knows what we are talking about. Not everyone would be able to understand I was talking about a tree from my description, but if I say the word tree, everyone has a clear image in their head of what I am talking about. 4Data Abstraction Data stored in variablesBits are a lower level of abstraction

Procedural AbstractionHiding the details (encapsulation) of a complex task under a name with parameters.

Two Different Senses of Abstraction#5

Lesson 1: Number Bases: Binary, Octal, Decimal and Hexadecimal

6Think Pair ShareWhy do use binary numbers instead of decimal numbers? 7Introducing Binary to StudentsWhat are some of the ways that you introduce binary numbers to your students? Use Think-Pair-Share to get teachers talking about the different ways that they introduce binary numbers to students.

Use manipulatives and kinesthetic learning activities.

Share some of the ideas in the module as well as the binary calculator (demonstrate), binary magic cards (get a link for this),

8Activity 1Count the Dots9Use index cards to create the following 5 cards.

Counting Dots Activity

#Teachers will create the cards above. 10Each card represents a place value in binary.

Counting Dots Activity

2423222120#Teachers will create the cards above. 11Just like the decimal number place values are 1, 10, 100, 1000 The binary number place values are 1, 2, 4, 8, 16,

Counting Dots Activity

168421#Explain that these are the place values for binary.

12How would we use this to convert the binary number 11111 to decimal?

Counting Dots Activity

16842111111#Given the binary number 11111 we can figure out the decimal equivalent by counting the dots. 11111 = 31

13Convert the binary number 01011 to decimal.

Counting Dots Activity16842101011

#Given the binary number 01011 we can figure out the decimal equivalent by counting the dots. 01011 = 11

14What is Digital?

#15

Activity 3Using Binary for Text16Using Binary for TextUse this subset of the ASCII codes to decode this message. http://www.asciitable.com/

43 53 20 52 4F 43 4B 53 21

#Participants need to have access to an ascii chart. http://www.asciitable.com/ The message is: CS ROCKS.17Decoding ExtensionsBrainstorm ideas for how you can extend this activity.Pair this with Creativity/Collaboration/Algorithms have students work in pairs to create their own number system. Can they create an algorithm to be used in creating ANY number system? How is this adding abstraction to this concept of data? 18

Activity 4Using Binary for Images19What are the differences between these two pictures?

#Discussion ideas and topics: One picture is color and one is black and white.

How does the computer know to display one picture as color and one as black and white? Explain how a picture is a collection of picture elements or pixels. Each color is made up of a red, green and blue value that is between 0 and 255. Three bytes or 24 bits to represent a color. This makes 256^3 or 16.8 million color combinations.

20Pixels and Color Codes

#What bits would be used to represent this color?

What else can we talk about with students? Compression? Lossy vs lossless (Big Idea 3: Data)

Given a black and white photo can you convert it back to color? Converting from color to grayscale requires us to average the r, b, g values for each pixel. The values for the grayscale version of the pixel above is a pixel with r = 108, b = 108 and g = 108. What type of conversion would this be? Lossy or Lossless? It would be Lossy, because there is no way to take a pixel with values of 108, 108 and 108 to get back to 208, 58, and 58.

Can you think of a picture effect that would be lossless? One that you would be able to undo? Negative: 255 r = nr; r = 255 nr

21

Lesson 2: Procedural Abstraction Using Turtle Primitives

22Think Pair ShareHow do you take your students from concrete examples to abstract formulas that use variables to do the work? 23Activity 2Drawing a Square24On your graph paper identify the point (0, 0) It really doesnt matter where you put this, but so we dont run out of room, put it some where in the center of the paper. Commands:penDown() puts the pencil down at the starting locationmove() moves 10 units in the direction the turtle is facingturn() turns the turtle 90 degrees clockwisepenUp() lifts the pen off of the paper. Start the turtle at (0,0) facing East. Setting up the Graph#25penDown()move()move()turn()move()move()turn()move()move()turn()move()move()turn()penUp()Graphing Turtle Movements

#26Turn To Your PartnerHow are we demonstrating the use of abstraction in the code we just explored? Through the use of methods. We dont need to know the complex code behind how we are able to use move() and have our turtle move forward 10 units. 27

Think Pair ShareWhat would your next step be in developing abstraction with your students? 28

Activity 3drawSquare50x50()How does the code change so that we are now drawing a larger square? 29penDown()move()move()turn()move()move()turn()move()move()turn()move()move()turn()penUp()Modify to Make a 50x50 Square#How does the code change so that we are now drawing a larger square? Name the procedure.30penDown()move()move()move()move()move()turn()move()move()move()move()move()turn()

Modify to Make a 50x50 Squaremove()move()move()move()move()turn()move()move()move()move()move()turn()penUp()#How does the code change so that we are now drawing a larger square? Name the procedure.31drawSquare50x50(){penDown()move()move()move()move()move()turn()move()move()move()move()move()turn()

Modify to Make a 50x50 Squaremove()move()move()move()move()turn()move()move()move()move()move()turn()penUp()}#How does the code change so that we are now drawing a larger square? Name the procedure.We can reuse this procedure and make multiple squares of size 50. We have encapsulated the details of the drawSquare50x50() and now can just give the command. 32drawSquare50x50(){penDown()move(50)turn()move(50)turn()move(50)turn()move(50)turn()penUp()}

Modify to Make a 50x50 Square#Use the move(50) to simplify the code. 33

Activity 5Student Practice and Homework34drawSquare50x50(){penDown()move(50)turn()move(50)turn()move(50)turn()move(50)turn()penUp()}

Modify to Make a 60x60 SquaredrawSquare60x60(){penDown()move(60)turn()move(60)turn()move(60)turn()move(60)turn()penUp()}

#What if we want the size to be 60 x 60 instead?

What about 30x30? Number of procedures required to represent the different sizes that we can draw for a square would be infinite.

Generalization? Use a variable 35drawSquare50x50(){penDown()move(50)turn()move(50)turn()move(50)turn()move(50)turn()penUp()}

Making a General drawSquare(x)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()}

#What if we want the size to be 60 x 60 instead?

What about 30x30? Number of procedures required to represent the different sizes that we can draw for a square would be infinite.

Generalization? Use a variable What is changing between the different drawSquare procedures? This is the variable. Use a parameter to get the value from the user. 36

Activity 7Draw Triangle Procedure37Writing 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 ShareHow many degrees should we turn to make a triangle? Try it. How does the code change so that we are now drawing a larger square? Is there a general formula that we can use to determine the turn amount? 39

Turn Amount for TriangleIs 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? #40ExtensionStudents can practice using parameters to create all sorts of draw procedures including a general drawPolygon() procedure.41

Activity 8makeFace() Procedure42Writing makeFace() ProcedureHave students use the procedure that they have written to create a picture, such as a face. Some other ideas: flower, arrow, house.

#43Summative AssessmentPage 33 of the module. Includes short answer, multiple choice and application questions.44