Operators, Expressions and Assignment Calculating Things...

Slides:



Advertisements
Similar presentations
2.1 Program Construction In Java
Advertisements

Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
JavaScript, Third Edition
Fall 2006AE6382 Design Computing1 Relational and Logical Operators Use relational operators to test two values Work with values of true and false Compare.
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
1 MATERI PENDUKUNG OPERATOR Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
CSI 101 Elements of Computing Spring 2009 Lecture #1 – From Math to Computers Wednesday, January 21, 2009.
Math is a language, learn the words!
Multiplying, Dividing, and Simplifying Radicals
Math 002 College Algebra Final Exam Review.
Expressions Objective: EE.01 I can write and evaluate numerical expressions involving whole number exponents.
Jon Curwin and Roger Slater, QUANTITATIVE METHODS: A SHORT COURSE ISBN © Cengage Chapter 2: Basic Sums.
2440: 211 Interactive Web Programming Expressions & Operators.
Demonstrate Basic Algebra Skills
Review for Mid-term! October 26, Review Homework Worksheet True or False Operators are symbols that perform specific operations in Visual Basic.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Visual Basic.NET BASICS Lesson 4 Mathematical Operators.
Tools of Algebra : Variables and Expressions; Exponents and PEMDAS; Working with Integers; Applying the Distributive Property; and Identifying Properties.
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
Variables Tutorial 3c variable A variable is any symbol that can be replaced with a number to solve a math problem. An open sentence has at least one.
Basic Operators. What is an operator? using expression is equal to 9. Here, 4 and 5 are called operands and + is the operator Python language supports.
Solving Linear Equations To Solve an Equation means... To isolate the variable having a coefficient of 1 on one side of the equation. Examples x = 5.
Algebraic Expressions Unit 1-1. Key Words:  Algebraic Expression: An expression that contains at least one variable. Ex. 2x 3x 2 + 3y – 5  Like Terms:
Equation Jeopardy Add Mixed Multiply/ Divide Fractions Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500 Final Jeopardy Subtract.
CPS120: Introduction to Computer Science Operations Lecture 9.
Mathematical Calculations in Java Mrs. G. Chapman.
Unit 2, Lesson 2: The Distributive Property and Factoring.
Lesson - 7. Operators There are three types of operators: Arithmetic Operators Relational and Equality Operators Logical Operators.
Unit 6 Math Vocab By: Marshall Lockyer. Constant Term A constant term is a term in an equation that does not change Example: a = 6 + b : In this case,
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
MM150 Unit 3 Seminar Agenda Seminar Topics Order of Operations Linear Equations in One Variable Formulas Applications of Linear Equations.
Assignment statement: Assigns a value to a variable Variable must appear on the left side, value on the right side of the assignment operator Right side.
Solving Equations. The purpose of this tutorial is to help you solve equations. As you move through the tutorial the examples will become more complex.
Mathematical Calculations in Java Mrs. C. Furman.
Arithmetic Expressions Addition (+) Subtraction (-) Multiplication (*) Division (/) –Integer –Real Number Mod Operator (%) Same as regular Depends on the.
By: Mr. Baha Hanene Chapter 6. LEARNING OUTCOMES This chapter will cover the learning outcome 02 i.e. 2.Use basic data-types and input / output in C programs.
Lesson 1.4 Equations and Inequalities Goal: To learn how to solve equations and check solutions of equations and inequalities.
Doing math In java.
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
1 karel_part3_ifElse_HW Conditional Statements A Mathematical look Relational operators < less than greater than >= greater.
CSCI 1100/1202 January 18, Arithmetic Expressions An expression is a combination of operators and operands Arithmetic expressions compute numeric.
Dr. Sajib Datta Jan 21,  Declare a variable ◦ int height; [note that no value is still assigned]  Assign a variable a value ◦ height =
 Scientific notation is simply a method for expressing, and working with, very large or very small numbers. It is a short hand method for writing numbers,
Single-Step Equations Addition/Subtraction Multiplication/Division Substitution Simplifying Expressions.
Complex Numbers and Equation Solving 1. Simple Equations 2. Compound Equations 3. Systems of Equations 4. Quadratic Equations 5. Determining Quadratic.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
CompSci 230 S Programming Techniques
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Based on slides by Shawn.
CMSC201 Computer Science I for Majors Lecture 03 – Operators
CMSC201 Computer Science I for Majors Lecture 04 – Expressions
Students will solve two step equations (12-4).
Assignment statement:
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
Assignment statement and Arithmetic operation 2
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Operators and Expressions
Arithmetic Operator Operation Example + addition x + y
Computers & Programming Languages
Winter 2018 CISC101 11/22/2018 CISC101 Reminders
Arithmetic Expressions & Data Conversions
Chapter 3: Selection Structures: Making Decisions
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
OPERATORS in C Programming
OPERATORS in C Programming
Arithmetic Expressions & Data Conversions
Introduction to Python
Presentation transcript:

Operators, Expressions and Assignment Calculating Things...

Expressions l Expressions are used to calculate values: 8 * l These values are often loaded into variables: X = 8 * 9Y = l Variables can be used in Expressions: X = 8 * YZ = X - 13

One Value Per Variable! l Variables hold a single value. l A variable can occur on both sides of an equation: X = X + 1 Y = Y * X / (7 - Y) l This means: l take the value out l Use it to calculate the new value. l Put the new value in the variable.

Expressions and Operators l Expressions are built up using operators and operands. l Depending on the operators used and the purpose of the expression, they fall into three general groups: Mathematical Comparison Logical l These types may be mixed.

Kinds of Expressions l Mathematical Expressions Used to calculate values. l Comparison Expressions Compare two values and evaluate a relationship between them. l Logical Expressions Combines comparison expressions.

Math Operators in Visual Basic ^ Power (Exponentiation) * Multiplication / Division (that rounds) \ Division (that truncates) Mod Modulo (Remainder) + Addition - Subtraction

Why two operators for division? l Most languages have one, and it truncates the value given it. Truncation means removing any fractional part from a number > >3 VB has the truncating division (backslash) to be consistent with other languages. This is known as integer division.

The VB Division l VB has a rounding division (forward slash) to be consistent with your expectations. l In almost every circumstance you’ll want to use the forward slash operator. 7 / 8->1 8 / 5->2

Question: l What is the operator for Exponentiation? A.* B.^ C.** D.~ E.None of the above.

What is Modulo? It gives the remainder of a division operation. You can calculate it for yourself like this: X mod Y => (X / Y - Floor(X / Y)) * Y Or, you can remember long division.

Long Division This is the Remainder

Order of Precedence of Operators ( )Parenthesis ^ Exponentiation - Negation * / Multiplication, Division \ Integer Division Mod Modulo + - Addition, Subtraction

Examples of Math Expression l X = The value 2 is loaded into variable X l Y = X * 2 The value in X is multiplied by 2 and the result is loaded into Y, so Y will hold 4. l Z = X * 3 + Y ^ 2 The value in Y is raised to the power 2. The value in X is multiplied by 3. The results are added and loaded into Z.

Something a little more complicated M=3/Y+2*Z^X\2-4Mod7*-3^(5*.2) HUNH??????????

Step by Step Given: X = 2, Y = 4, and Z = 10 M = 3 / Y + 2 * Z ^ X \ Mod 7 * -3 ^ (5 *.2) Parenthesis: (5 *.2) => 1.0 M = 3 / Y + 2 * Z ^ X \ Mod 7 * -3 ^ 1 Exponentiation: Z ^ X => 100, -3 ^ 1 => -3 M = 3 / Y + 2 * 100 \ Mod 7 * -3

Step by Step by Step M = 3 / Y + 2 * 100 \ Mod 7 * -3 Now do the division and multiplication, left to right: 3 / Y =>.75, 2 * 100 => 200, 7 * -3 => -21 M = \ Mod -21

Step by Step by Step... M = \ Mod -21 Then the Integer Division: 200 \ 2 => 100 M = Mod -21 Then the modulus operator: 4 Mod -21 => 4 M =

Step by Step by Step... Finally, do the addition and subtraction left to right: => , => M = So the answer is 96.75, which is loaded into variable M.

Question: l What value will be loaded into Z from the following expression. l Z = / 2 ^ 2 A.49 B.8 C.32 D.3.5 E.None of the above.

Comparison Operators l There are six basic comparison operators <Less Than >Greater Than <=Less Than or Equal To >=Greater Than or Equal To =Equal To Not Equal To

Something you don’t have to know! l There are two esoteric comparison operators: LikeCompares Strings IsCompares Objects You’re not responsible for knowing these and we’ll not be covering them.

Use of Comparison Operators Comparison Operators ask questions: Is X bigger than Y?:X > Y Is Y at least as large Z?:Y >= Z Is X the same as Z?:X = Z

Values Returned l Comparison operators all return one of two values: True or False. l Either the relationship holds or it doesn’t Either a > b, so the result is True or a isn’t greater than b and the result is False

Representing True & False l True is represented in VB as -1 l Which is in binary l False is represented in VB as 0 l Which is in binary

Question: l If I want to know if X is greater than 5, I would use: A. X = 4.9 B.X>= 5 C.X < 5 D.X <> 5 E.None of the above

Logical Operators l There are three logical operators: AndOrNot l Used to combine comparison and logical expressions for more complex situations.

Use of Logical Operators l To enroll at WSU you must have a high school diploma and have lots of money: HighSchool = “Yes” And Money > $1000

More Logical Operators l To graduate from WSU you must have 135 credits, an acceptable GPA and a be enrolled in a college: Credits >= 135 And GPA > 2.0 And Not College = “None” Credits >= 135 And GPA > 2.0 And College <> “None”

Still More Logical Operators l To pay for your Ultra Deluxe Slice-o-Matic in three easy payments you need either $120 in cash or a credit card. CreditCard = “Yes” Or Cash >= 120

Question: l If I wanted to know if A is greater than B and that C is not greater than D I would use: A.A > B and C > D B.A > B and not C > D C. A > B and C <= D D.Answer B and Answer C E.None of the above

Values of Logical Expressions l Logical expressions return either True or False, no matter how complex they become. True False

Checking for correctness? l Perform operations by hand l Compare Answers l Repeat

Example Programs l Evaluating an Equation The quadratic formula: