Arithmetic Expressions

Slides:



Advertisements
Similar presentations
Arithmetic Calculations
Advertisements

Types and Arithmetic Operators
Built-in Functions & Arithmetic Expressions.
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
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.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: Numeric Data *Variables *Numeric data.
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
1  Ex: Declare a variable to store user’s age: int age; Prompt the user to enter his/her age: printf (“ How old are you? “); Read / scan the entered value.
What is a variable?  A variable holds data in memory so the program may use that data, or store results.  Variables have a data type. int, boolean, char,
Advanced Decisions and Loops Chapter Some Simple Schoolroom Statistics.
Variable Declaration  It is possible to declare multiple variables of the same data type on the same line.  Ex. double hours, rate, total;  Variables.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
LESSON 6 – Arithmetic Operators
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Assignment Statements Operator Precedence. ICS111-Java Programming Blanca Polo 2 Assignment, not Equals  An assignment statement changes the value of.
PRESENTATION 11 What Is Algebra. ALGEBRAIC EXPRESSIONS An algebraic expression is a word statement put into mathematical form by using variables, arithmetic.
Mathematical Calculations in Java Mrs. G. Chapman.
CSC 107 – Programming For Science. The Week’s Goal.
Chapter 6 Mathematical Operations. 6.1 Mathematical Expressions In mathematics this expression is valid 0 = -4y + 5 It is invalid in programming Left.
Mathematical Calculations in Java Mrs. C. Furman.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Arithmetic OperatorOperationExample +additionx + y -subtractionx - y *multiplicationx * y /divisionx / y Mathematical FormulaC Expressions b 2 – 4acb *
This will all add up in the end. Assignment operator =Simple Assignment operator Arithmetic Operators +Additive operator – Subtraction operator * Multiplication.
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)
Doing math In java.
CSCI 1100/1202 January 18, Arithmetic Expressions An expression is a combination of operators and operands Arithmetic expressions compute numeric.
PROGRAMMING INFORMATION. PROCEDURES IN PYTHON Procedures can make code shorter, simpler, and easier to write. If you wanted, for example, to use a certain.
1 Lecture Three I/O Formatting and Arithmetic Dr. Sherif Mohamed Tawfik.
Chapter INTRODUCTION Data Types and Arithmetic Calculations.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
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.
CSC Programming for Science Lecture 5: Actual Programming.
2.3 Output Formatting. Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf.
Arithmetic Expressions
Variables, Operators, and Expressions
Expressions.
Expressions.
numerical coefficient
BIL 104E Introduction to Scientific and Engineering Computing
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.
Assignment and Arithmetic expressions
Primitive Data, Variables, Loops (Maybe)
Chapter 7 Objectives Define basic terms in algebra: integer, number statement, expression, and coefficient Learn the relationships between positive and.
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Arithmetic Operator Operation Example + addition x + y
Arithmetic operations, decisions and looping
Doing things more than once
Basic Notions Review what is a variable? value? address? memory location? what is an identifier? variable name? keyword? what is legal identifier? what.
Number and String Operations
Chapter 8 JavaScript: Control Statements, Part 2
With Assignment Operator
CS 240 – Lecture 9 Bit Shift Operations, Assignment Expressions, Modulo Operator, Converting Numeric Types to Strings.
A First Book of ANSI C Fourth Edition
Arithmetic Expressions & Data Conversions
C Operators, Operands, Expressions & Statements
Using Functions
THE COMPUTE STATEMENT Purpose: performs mathematical calculations
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.
CS150 Introduction to Computer Science 1
Data Types and Expressions
Primitive Types and Expressions
Just Enough Java 17-May-19.
Class code for pythonroom.com cchsp2cs
Data Types and Expressions
Arithmetic Expressions & Data Conversions
Data Types and Expressions
Presentation transcript:

Arithmetic Expressions http://www.alice.org/resources/lessons/arithmetic-expressions/

Arithmetic Expression What is an Arithmetic Expression 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

Arithmetic Expression Operand Types A numeric operand can be either A whole number (integer) Or a floating pt number (decimal number). This also includes functions that resolve to a whole number or decimal Get distance, get width, and get double or integer from user

Arithmetic Expression Operators Arithmetic operators are mathematical function that takes two operands and perform a calculation on them such as: Addition + Subtraction - Multiplication * Division / Remainder (mod) % Alice also supports mathematical functions that can be performed such as resolving between a minimum or maximum value, getting the square root, or even sine or cosine.

Arithmetic Expression Creating Arithmetic Expression In Alice these can be accessed using the Math drop down menu item when modifying a parameter that uses the whole number or decimal data type. You first select the operator and then select the operands. You can use placeholders that you then replace with functions or variables. Alice in most cases assumes a binary expression but you can string multiple arithmetic expressions together by further modifying operands.

Arithmetic Expression Common Uses of Arithmetic Expression Common uses of mathematical equations in Alice are: To modify a distance or spatial relationship To calculate a number of iterations for a count loop To increment or decrement a variable

Arithmetic Expression Calculating a Distance In Alice the location of an object in space is often unknown due to the way you build your scene. Using the get distance function to determine how far to have something move can be an easy way to animate an object moving the distance. However because using the getDistance functions calculates the value based on the middle of the objects this function by itself will stack the objects on top of each other. A simple arithmetic expression can help you modify the statement to have the object stop just short of the target object.

Arithmetic Expression Calculating Number of Iterations In animation you may want to have a looping animation run an unknown amount of times to match another animation: having a certain amount of walking motions happen depending on the distance traveled Having the mouth move to match the duration of a dialogue You can have the number of loops = the distance or duration of a dialogue / the duration or distance of the walk or talk cycle *Example uses integer divide to round off a whole number to be compliant with Loop data type

Arithmetic Expression Incrementing and Decrementing When using variable you will often want to increment or decrement the value when events happen in the world such as: TimeVariable - 1 to count down based on a timer event ScoreVariable + 1 to track score based on a triggering event ItemsCollected + 1 to track an item count based on a triggering event *example shows a timer event triggered every second that decrements the time left variable