programming: putting together the pieces built-in questions and expressions alice

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

Upload: sheena-owen

Post on 13-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

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

Programming: Putting Together the Pieces

Built-in Questions and Expressions

Alice

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

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

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

Four Primary Pieces

Instruction

Control Structure

Question

Expression

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

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

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

Control Structure

A control structure is a statement that controls which statements are executed and in what order.

Examples: Do in order

Do together

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

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…

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

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?

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

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.

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

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

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

Demo

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

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

CodeNote 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.

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

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

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

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.

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

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 /

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

Demo

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

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

Assignment

Read Chapter 3-1, Questions and Expressions

Lab 3-1