Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming: Putting Together the Pieces Built-in Questions and Expressions Alice.

Similar presentations


Presentation on theme: "Programming: Putting Together the Pieces Built-in Questions and Expressions Alice."— Presentation transcript:

1 Programming: Putting Together the Pieces Built-in Questions and Expressions Alice

2 Putting together the pieces A major part of learning how to program is figuring out how to "put together the pieces" that compose a program. The purpose of this lecture (and the next) is to show some primary pieces used in creating programs demonstrate how to put the pieces together

3 Four Primary Pieces Instruction Control Structure Question Expression

4 Instruction An instruction is a statement that executes (is carried out by the computer at runtime). In Alice, an instruction makes objects perform a certain action. Examples: snowman turn to face snowwoman helicopter turn left 0.25 revolutions

5 Control Structure A control structure is a statement that controls which statements are executed and in what order. Examples: Do in order Do together

6 Questions A question is a function that checks a condition or computes a value. In Alice, you can ask questions about the properties of objects Is the snowwoman's face red? the relationship of one object to another What is the distance between the mummy and pyramid? the world What key (on the keyboard) was pressed? Let's look at an example…

7 Problem Example A Hollywood movie set. The camera angle influences our perception of the scene. Is the mummy taller than the pharaoh? How far is the mummy from the pharaoh?

8 Built-in Questions The Alice system provides some built-in questions. Categories proximity size spatial relation point of view other This example illustrates some built-in proximity questions.

9 Values An answer to a question is a value. The type of value depends on the kind of question asked. In our example, we want to ask the question: What is the distance of the mummy to the pharaoh? We expect to get a number value. It could be a whole number or a fractional value, such as 3 meters or 1.2 meters

10 Demo A program will be developed in class to illustrate the use of a question to move the mummy to the pharaoh.

11 Code Note that the question "piece" of the program does not "stand alone." In this example, the question is part of a move instruction The value provides the distance the mummy will move.

12 Types of Values In our example, we used a question that has a number value. Other types of values include: Boolean true, false String "Oh, Yeah!" Object snowman, helicopter Position in the world (0, 0, 0) – the center of an Alice world

13 Problem: Collision When the program is run, the mummy collides with the pharaoh. The problem is the distance between two objects is measured center-to-center. One way to avoid a collision is to subtract a small number (perhaps 1) from the distance.

14 Expressions An expression is a math or logic operation on numbers or other types of values Alice provides math operators for common math expressions: addition + subtraction  multiplication * division /

15 Demo A modification of the program to illustrate the use of an expression.

16 Assignment Read Chapter 3-1, Questions and Expressions Lab 3-1


Download ppt "Programming: Putting Together the Pieces Built-in Questions and Expressions Alice."

Similar presentations


Ads by Google