Rational Expressions. relational operators. logical operators

Slides:



Advertisements
Similar presentations
1 Chapter 3:Operators and Expressions| SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2006 | Last Updated: July 2006 Slide 1 Operators and Expressions.
Advertisements

Control Structures Control structures are used to manage the order in which statements in computer programs will be executed Three different approaches.
If Statements & Relational Operators Programming.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
1 9/15/06CS150 Introduction to Computer Science 1 Combined Assignments, Relational Operators, and the If Statement.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
2440: 211 Interactive Web Programming Expressions & Operators.
Simple Data Types and Statements. Namespaces namespace MyNamespace { // …. { MyNamespace::func1() using namespace OtherNamespace; Comments: // /* xxxx.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
CS31: Introduction to Computer Science I Discussion 1A 4/9/2010 Sungwon Yang
Rational Expressions and selection structures Relational operators Logical operators Selection structures.
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.
Pseudocode When designing an ALGORITHM to solve a problem, Pseudocode, can be used. –Artificial, informal language used to develop algorithms –Similar.
CPS120: Introduction to Computer Science Operations Lecture 9.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
Selection Relational Expressions A condition or logical expression is an expression that can only take the values true or false. A.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X1 Chapter 3 Control Statements.
15-Nov-15 All the Operators. operators.ppt 2 Precedence An operator with higher precedence is done earlier (precedes) one with lower precedence A higher.
Conditional Expressions
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Data Types Declarations Expressions Data storage C++ Basics.
Selection Control Structures (L08) * Selection Criteria * if Statements * The if-else Statement Selection Control Structure Dr. Ming Zhang.
Chapter 4 October 22, The If Statement Programs make decisions If(condition){ Statement(s); } Condition  boolean expression Evaluates to either.
Chapter 7 Conditional Statements. 7.1 Conditional Expressions Conditions - compare the values of variables, constants and literals using one or more relational.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
CMSC 104, Version 9/011 Relational and Logical Operators Topics Relational Operators and Expressions The if Statement The if-else Statement Nesting of.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
STRUCTURED PROGRAMMING C++ Operators. Content 2  C++ operators  Assignment operators  Arithmetic operators  Increment and decrement operators  Decision.
Department of Electronic & Electrical Engineering Lecture 3 IO reading and writing variables scanf printf format strings "%d %c %f" Expressions operators.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Rational Expressions relational operators logical operators order of precedence.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
Relational Operator and Operations
CSE 220 – C Programming Expressions.
Operators And Expressions
Operators and Expressions
Section 3 Review Mr. Crone.
INSPIRING CREATIVE AND INNOVATIVE MINDS
More important details More fun Part 3
Data Types, Identifiers, and Expressions
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.
Expression Review what is the result and type of these expressions?
Data Types, Identifiers, and Expressions
All the Operators 22-Nov-18.
Relational Operators Operator Meaning < Less than > Greater than
All the Operators 4-Dec-18.
Computer Science 210 Computer Organization
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.
Expressions.
SE1H421 Procedural Programming LECTURE 4 Operators & Conditionals (1)
All the Operators 6-Apr-19.
All the Operators 13-Apr-19.
Relational and Logical Operators
Relational and Logical Operators
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
OPERATORS in C Programming
Flow of Control.
Relational and Logical Operators
OPERATORS in C Programming
Chapter 12 Variables and Operators
Presentation transcript:

Rational Expressions. relational operators. logical operators Rational Expressions relational operators logical operators order of precedence

Expressions any combination of variables, constants and functions that can be evaluated to yield a result typically involve operators

Expressions 5 x x + y func(12.05, a, “Yvonne”) cnt++ a = 3 + j

Relational Expressions compare operands used in decision making evaluate to 1 (true) or 0 (false)

Relational Operators less than < greater than > less than or equal to <= greater than or equal to >= a - b < 0 is equivalent to (a - b) < 0

Relational Expressions Operand Relational Operand operator price < 34.98 expression * * *

Relational Expressions Operand Relational Operand operator... ‘Z’ < ‘K’ expression

Values of Relational Expressions

Evaluating Expressions int i = 1, j = 2, k = 3; i < j - k b i * *

Evaluating Expressions int i = 1, j = 2, k = 3; -i + 5 * j >= k + 1 i i i i b * * * * *

Evaluating Expressions int i = 1, j = 2, k = 3; double x = 5.5, y = 7.7 x - y <= j - k + 1 (x - y) <= ((j - k) + 1) i r i b * * *

Relational Operators Examples Valid a < 3 a > b -1.1 >= (2.2 * x + 3.3) a < b < c // syntactically correct but confusing Not Valid a =< b // out of order a < = b // space not allowed a >> b // shift expression * *

Equality Operators Equal to = = Not Equal to != Note this! * * *

Values of Equality Expressions

Equality Operators Examples Valid c == 'A' k != -2 y == 2 * z - 5 Not Valid a = b // assignment statement a = = b - 1 // space not allowed y =! z // this is equivalent to y = (!z) * *

Numerical Accuracy Many decimal numbers cannot be exactly represented in binary by a finite number of bits. Thus testing for exact equality can fail. Use the technique: |operand1 - operand2| < epsilon Ex. x/y == 17 abs(x/y - 17) < 0.000001 *

Logical Operators Negation (unary) ! Logical and && Logical or || *

Logical Operators: Examples Valid a && b a || b && c !(a < b) && c 3 && (-2 * a + 7) Not Valid a && // one operand missing a | | b // extra space not allowed a & b // this is a bitwise operation &b // the address of b * *

Logical Operators: Examples int a = 0, b = 3, c = 1, d =4; a && !c || d b F b F b T * * *

Logical Operators: Examples int a = 0, b = 3, c = 1, d =4; a && b || !c || d b F b F b T b F * * * *

Logical Operators Expression Expression Equivalent !(a == b) !(a == b || a == c) !(a == b && c > d) a != b a != b && a != c a != b || c <= d * * *

Logical Expressions: Boolean This is for version 4 only. typedef int boolean; const boolean TRUE = 1; const boolean FALSE = 0; ver. 5 & 6: bool is a data type

Truth Table for &&, ||, !

Operator Precedence and Associativity ! not arithmetic relational logical

Logical Expressions b i r b b b b char cv; double dv = 6.5; int iv = 4; ! (cv == ‘z’) && (abs(dv) || iv) || pow(3,2) b F b T i b T r b T b T * * * * * * *

The Empty Statement The empty statement is written as a semicolon. Example: ; // an empty statement Other statements: a = b; // an assignment statement a + b + c; // legal, no useful work done cout << a() << "\n"; // a function call

Common Errors! = = means equality = used for assignment FALSE is zero TRUE is nonzero Boolean operators give a Boolean result * *

Success comes before work only in the dictionary. End Note: Success comes before work only in the dictionary. Success comes before work only in the dictionary. Success comes before work only in the dictionary.