1 / 18

Built-in Functions & Arithmetic Expressions

Built-in Functions & Arithmetic Expressions. Recall :. A curupira is playing soccer in the rainforest. The curupira has a soccer ball and will kick the soccer ball toward a pond in the forest. Each kick causes the soccer ball to move forward a random distance .

temima
Download Presentation

Built-in Functions & Arithmetic Expressions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Built-in Functions & Arithmetic Expressions

  2. Recall: • A curupira is playing soccer in the rainforest. The curupira has a soccer ball and will kick the soccer ball toward a pond in the forest. Each kick causes the soccer ball to move forward a random distance. • If the curupira gets the soccer ball in the water, the curupiradoes a dance, or else he disappears in disgust

  3. Where we left off Working on running to the soccer ball Do in order curupira runs to soccer ball curupira kicks the soccer ball a random distance If soccer ball is in the water, curupira dances else curupira disappears

  4. Recall from previous session… Curupira moves forward, but how far? How can we be sure that 3 meters is the necessary distance?

  5. Functions • A function asks a question (to check a condition or compute a value). • In Alice, a function is used to get the information we need concerning • the properties of objects • Is the water blue? • the relationship of one object to another • What is the distance between the curupira and the soccer ball?

  6. Alice 3 Methods Panel Performs an action; does NOT compute and return a value Computes and returns a value; does NOT perform an action

  7. Return a value of a specific data type Built-in functional methods Property values Decimal Number Boolean String

  8. Video: Calling a function • This video illustrates slide 10

  9. Calling a functional method We use the getDistanceTofunction to determine the distance between the curupira and the targetobject

  10. Embedded within a statement A call to a function is embedded within a Example: Calling getDistanceTo The return value (distance value returned by the function)is used as the value for distance in the move statement

  11. Why? • The problem is that distance between two objects is measured center-to-center. • One way to solve this problem is to subtract a small number from the distance.

  12. Arithmetic Expressions Traditional math and formula computations are implemented as arithmetic expressions in a computer program. An arithmetic expression is a combination of operators and operands evaluates to a numeric value

  13. A numeric operand can be either • A whole number (integer) • Or a floating pt number (decimal number).

  14. Arithmetic operators are symbols that can easily be typed on a keyboard Addition + Subtraction - Multiplication * Division / Remainder (mod) %

  15. Video: 18. Building Arithmetic Expressions • This video illustrates slides 18-20

  16. Arithmetic expressions in Alice Click pull-down menu arrow for getDistanceToand select Math Then, build an expression from the cascading menus.

  17. Binary operation Cascading menus assume a binary operation Operand Operator Operand Resulting statement:

  18. Complete runToBall procedure

More Related