Expressions.

Slides:



Advertisements
Similar presentations
Operators and Arithmetic Operations. Operators An operator is a symbol that instructs the code to perform some operations or actions on one or more operands.
Advertisements

3. S/E with Control Structures 3.1 Relational Operators and Expressions 3.2 If and if-else Statements 3.3 The Type Double 3.4 Program Design with the While.
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
1 Pertemuan 04 Expression Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
ECE122 L7: Conditional Statements February 20, 2007 ECE 122 Engineering Problem Solving with Java Lecture 7 Conditional Statements.
Program Control Dilshad M. Shahid New York
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
More about Numerical Computation CS-2301, B-Term More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials.
Fall 2006AE6382 Design Computing1 Relational and Logical Operators Use relational operators to test two values Work with values of true and false Compare.
Chapter 4: Basic C Operators
Expressions creating information. topics  operators: precedence, associativity, parentheses, overloading  operands: side-effects, coercion  arithmetic,
Ryan Chu. Arithmetic Expressions Arithmetic expressions consist of operators, operands, parentheses, and function calls. The purpose is to specify an.
Computer Science 101 The Boolean System. George Boole British mathematician ( ) Boolean algebra –Logic –Set theory –Circuits –Conditions in if.
XOR and XNOR Logic Gates. XOR Function Output Y is TRUE if input A OR input B are TRUE Exclusively, else it is FALSE. Logic Symbol  Description  Truth.
Decision Structures and Boolean Logic
© 2006 Pearson Education 1 Obj: to use compound Boolean statements HW: p.184 True/False #1 – 6 (skip 3)  Do Now: 1.Test your “Charge Account Statement”
Computer Science 210 Computer Organization Introduction to Boolean Algebra.
Selection Boolean What is Boolean ? Boolean is a set with only two values : –true –false true and false are standard identifiers in Pascal, called Boolean.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Lesson - 7. Operators There are three types of operators: Arithmetic Operators Relational and Equality Operators Logical Operators.
1 Operators and Expressions. Expressions Combination of Operators and Operands Example 2 * y + 5 Operands Operators.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Principles of Programming Chapter 4: Basic C Operators  In this chapter, you will learn about:  Arithmetic operators  Unary operators  Binary operators.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
CHAPTER FOUR Performing Calculations and Manipulating Data: Expressions.
Rational Expressions relational operators logical operators order of precedence.
 Type Called bool  Bool has only two possible values: True and False.
Principles of Programming - NI July Chapter 4: Basic C Operators In this chapter, you will learn about: Assignment operators Arithmetic operators.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
Operators & Expressions
7.2 Arithmetic Expressions
Computer Science 210 Computer Organization
Chapter 7: Expressions and Assignment Statements
Operators And Expressions
COMP205 IMPERATIVE LANGUAGES
Expressions and Assignment
University of Central Florida COP 3330 Object Oriented Programming
Rational Expressions. relational operators. logical operators
Sequence, Selection, Iteration The IF Statement
Section 7.1 Logical Operators
ITEC113 Algorithms and Programming Techniques
University of Central Florida COP 3330 Object Oriented Programming
Relational Operations
Data Types, Identifiers, and Expressions
Chapter 7: Expressions and Assignment Statements
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.
Topics The if Statement The if-else Statement Comparing Strings
Boolean Expressions & the ‘if’ Statement
September 7 Notes Boolean Algebra.
Topics The if Statement The if-else Statement Comparing Strings
OPERATORS (2) CSC 111.
Logical Operators & Truth Tables.
Data Types, Identifiers, and Expressions
Computers & Programming Languages
All the Operators 22-Nov-18.
Chapter 8 JavaScript: Control Statements, Part 2
Relational Operators Operator Meaning < Less than > Greater than
More about Numerical Computation
All the Operators 4-Dec-18.
Computer Science 210 Computer Organization
Associativity and Prescedence
Introduction to Programming – 4 Operators
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.
Logic of an if statement
All the Operators 6-Apr-19.
All the Operators 13-Apr-19.
Herbert G. Mayer, PSU CS Status 7/19/2015
Operator King Saud University
5.03 Apply operators and Boolean expressions
Presentation transcript:

Expressions

1. Arithmetic Expression: - It is composed of operands and arithmetic operations ( + , - , *, /, MOD). - Its result is a numeric value (e.g. 3 + 4 gives 7) - Operands may be numbers and/or identifiers that have numeric values e.g. x – y gives 4, if x is 6 and y is 2 x / 2 gives 6, if x 12 T MOD 2 gives 0 if T is any even number, and 1 if T is any odd number

2. Logical Expression: - It is called also Boolean expression. - It is composed from operands and operators. - Operands are identifiers that have logical values - Its result is a logical value (true or false) (see later). - Operators are logical: AND , OR, NOT e.g. X AND Y a AND b OR c where X, Y, a, b, c are defined logical

3. Relational Expression: - It is composed from operands and operators. - Operands may be numbers and/or identifiers that have numeric values - Its result is a logical value (true or false). - Operators are relational operators: <, >, =, ≠, ≤, ≥ e.g. (a < b) gives true, if value of a is less than value of b false, if value of a is not less than value of b (x ≠ y) also gives true or false according to the values of x and y

NOTES A relational expression may contain arithmetic sub-expressions, e.g. ( 3 + 7 ) < (12 * 4 ) 2) A logical expression may contain relational and arithmetic sub-expressions, e.g. 1- x AND y AND ( a > b ) 2- (2 + t ) < (6 * w ) AND ( p = q )

Expressions are evaluated according to the precedence rule. Operator Precedence Expressions are evaluated according to the precedence rule. Precedence Rule: - Each operator has its own precedence that indicates the order of evaluation. - If the expression has operators of the same precedence, then the evaluation starts from left of expression to the right.

Precedence Description Operator Higher parentheses ( unary plus, unary minus, Not +, – , NOT *, /, MOD Binary plus, binary minus + , - <, <=, >, >= Equal, not equal = , != AND OR Lower Assignment 

Examples Find the value of the following expression: (1) 5 + 8 * 2 / 4 (1) 5 + 8 * 2 / 4 16 4 9 (This is the final result)

( 9 + 3 ) - 6 / 2 + 5 12 3 9 14 (this is the final result)

Evaluating Logical Expressions The truth table AND table AND True False True True False False False False

(2) OR table OR True False True True True False True False (3) NOT table NOT True False False True

Examples on Logical Expressions If x = True, y = False, z = False, find the value of the expression x AND y OR z x AND y OR z False False (the final result)

(2) If a = 3, b = 5, x = true, y = false, find the value of the expression: ( a < b ) AND y OR x True (the final result)