15-101 Built-in Functions & Arithmetic Expressions.

Slides:



Advertisements
Similar presentations
Types and Arithmetic Operators
Advertisements

Stepwise Refinement -- A procedure calls another procedure
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Computer Science 1620 Arithmetic. C++ Math we have seen how to use numbers in our program to represent data however, we can also manipulate this data.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: Numeric Data *Variables *Numeric data.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
Section 1.1 Numbers and Their Properties.
Sets and Expressions Number Sets
Algebra 1 Review: 1.1 Expressions and Formulas Objectives:
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
2440: 211 Interactive Web Programming Expressions & Operators.
Operators in Python. Arithmetic operators Some operators in Python will look familiar (+, -, *, /) Others are new to you (%, //, **) All of these do work.
7-1 Chapter 7.  Basic Arithmetic Verbs  Options Available with Arithmetic Verbs  COMPUTE Statement  Signed Numbers in Arithmetic Operations  Intrinsic.
Four Fundamental Pieces Instruction Control Structure Function Expression.
Variables & Random Number Generation.  A penguin is playing arctic basketball. The penguin has a basketball and will push the basketball toward.
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Mathematical Expressions, Conditional Statements, Control Structures
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
Programming: Putting Together the Pieces Built-in Questions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Functions Sec 8-11 Web Design. Objectives The Student will: Understand what a function is Know the difference between a method and a function Be able.
Arithmetic Expressions Addition (+) Subtraction (-) Multiplication (*) Division (/) –Integer –Real Number Mod Operator (%) Same as regular Depends on the.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Variables & Conditions.
4. EXPRESSIONS. Display the value of pi, to 5 decimal places, right justified, in 9 columns Read in someone’s height in feet and inches using.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Doing math In java.
Controlling Program Flow with Decision Structures.
CSCI 1100/1202 January 18, Arithmetic Expressions An expression is a combination of operators and operands Arithmetic expressions compute numeric.
Computer Science Up Down Controls, Decisions and Random Numbers.
What will each of the following lines print? System.out.println("number" ); number645 System.out.println("number" + (6 + 4)+ 5); number105 System.out.println(6.
Chapter 3 Math Operations. Objectives Use the assignment and arithmetic operators. Use operators in output statements. Explain the problem with division.
7 - Programming 7J, K, L, M, N, O – Handling Data.
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Programming: Putting Together the Pieces Built-in Functions and Expressions Sec 8-5 Web Design.
Obj: to recognize built-in functions and expressions HW: Read Section 3.1 and do HW4 Edmodo article due Sunday at 8pm Edmodo feedback due 8pm 10/17 Do.
Programming: Putting Together the Pieces Built-in Functions and Expressions Sec 8-5 Web Design.
Chapter 3: Variables, Functions, Math, and Strings
Chapter 3: Variables, Functions, Math, and Strings
Addition/ Subtraction
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Arithmetic operations & assignment statement
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Arithmetic Operator Operation Example + addition x + y
Arithmetic Expressions
Arithmetic Expressions & Data Conversions
C Operators, Operands, Expressions & Statements
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Using Functions
Math unit 1 review.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
THE COMPUTE STATEMENT Purpose: performs mathematical calculations
Alternate Version of STARTING OUT WITH C++ 4th Edition
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Chapter 9 Basic Algebra © 2010 Pearson Education, Inc. All rights reserved.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Arithmetic Expressions & Data Conversions
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Introduction to Python
Presentation transcript:

Built-in Functions & Arithmetic Expressions

 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 curupira scores a point and does a dance, or else he disappears in disgust Recall :

To start  Download and open the world you were working on from last session: - or - CurupiraSoccerRunToObject.a3p

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, score 1 point curupira dances else curupira disappears

Our implementation Curupira moves forward, but how far? How can we be sure that 1 meter is the correct distance?

Curupira does not run far enough

 In the PenguinBowling project, the penguin was positioned exactly 1 m from the pen – a known distance.  pushObject procedure moves this Penguin object forward 1 meter to collide with the target object  In the CurupiraSoccer project, the distance between the soccer ball and the curupira is unknown. Known vs Unknown Distance

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?

Alice 3 Methods Panel Performs an action; does NOT compute and return a value Computes and returns a value; does NOT perform an action Sets or gets a value that is stored in a property variable.

 Return a value of a specific data type Boolean Decimal Number Joints String Built-in functional methods

Calling a functional method  We use the getDistanceTo function to determine the distance between the curupira and the

Calling a functional method  Video demonstration of adding getDistanceToTile

Calling a functional method  A call to a function is embedded within a larger statement (that is, a call to a function is NOT a syntactically complete statement)  Example: Calling getDistanceTo  The return value (distance value returned by the function) is used as an argument in the move statement

Problem: Collision  When our program is run, the curupira seems to move through the ball – too much collision.

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

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

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

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

Arithmetic expressions in Alice  Click pull-down menu arrow for getDistanceTo and select Math  Build expression from the cascading menus.

Arithmetic expressions in Alice  Video demonstration of building an arithmetic expression

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

Complete runToBall procedure

Curupira does not move through the soccer ball