Rational Expressions relational operators logical operators order of precedence.

Slides:



Advertisements
Similar presentations
Types and Arithmetic Operators
Advertisements

Control Structures Control structures are used to manage the order in which statements in computer programs will be executed Three different approaches.
Expressions ► An expression can be a single variable, or can include a series of variables. If an expression includes multiple variables they are combined.
Lecture 071 CS 192 Lecture 7 Winter 2003 December 15-16, 2003 Dr. Shafay Shamail.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
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.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
CSCI 130 Chapter 4 Statements, Expressions, and Operators.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Ryan Chu. Arithmetic Expressions Arithmetic expressions consist of operators, operands, parentheses, and function calls. The purpose is to specify an.
CSci 125 Lecture 10 Martin van Bommel. Simple Statements Expression followed by semicolon Assignments total = n1 + n2; Function calls printf(”Hello.\n”);
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.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
1 Lecture 5: Selection Structures. Outline 2  Control Structures  Conditions  Relational Operators  Logical Operators  if statements  Two-Alternatives.
Rational Expressions and selection structures Relational operators Logical operators Selection structures.
Flow of Control Part 1: Selection
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.
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
These notes were originally developed for CpSc 210 (C version) by Dr. Mike Westall in the Department of Computer Science at Clemson.
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.
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.
1 Operators and Expressions. Expressions Combination of Operators and Operands Example 2 * y + 5 Operands Operators.
Selection Control Structures (L08) * Selection Criteria * if Statements * The if-else Statement Selection Control Structure Dr. Ming Zhang.
Chapter 4 Making Decision Csc 125 C++ programming language Fall 2005.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
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.
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.
Conditionals. Conditional Execution A conditional statement allows the computer to choose an execution path depending on the value of a variable or expression.
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.
Copyright © Curt Hill The C++ IF Statement More important details More fun Part 3.
 Type Called bool  Bool has only two possible values: True and False.
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
Rational Expressions. relational operators. logical operators
INSPIRING CREATIVE AND INNOVATIVE MINDS
Selections Java.
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.
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.
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.
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
OPERATORS in C Programming
Flow of Control.
OPERATORS in C Programming
Chapter 12 Variables and Operators
Presentation transcript:

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

Sample Expressions 5 A constant is an expression x A variable is an expression x + y Binary operator func(12.05, a, “Yvonne”) cnt++ Unary operator a = 3 + j The assignment operator! B = (a = 3 + j); Functions that return a value

Relational Expressions compare operands used in decision making evaluate to 1 (true) or 0 (false) Another legacy or “old” C. Newer versions of C++ have a Boolean variable type.

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 Because of precedence!

A Relational Expression Operand Relational Operand operator price < Expression The expression is either true or false 1 or 0 * * *

Relational Expressions Operand Relational Operand operator... ‘Z’ < ‘K’ Expression The expression is either true or false (In this case, it’s always false)

Values of Relational Expressions

Evaluating Expressions int i = 1, j = 2, k = 3; i < j - k * * i b 0 False The < operator has lower precedence than the - operator

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

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 Order of Evaluation  True

Inequality Operators Examples Valid a b -1.1 >= (2.2 * x + 3.3) a < b < c// syntactically correct but confusing Not Valid a = > b// shift expression (more operator overloading) * Becomes 1 < c or 0 < c

Equality Operators Equal to == Not Equal to != * * * Note this! Equality comparisons always use == Assignment always uses = The first is algebraic equality, not the two-step assignment operation!

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) < * 1/ …

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

Boolean Logic * && AND || 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 * Evaluate && before ||

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

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

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 * * * There are rules for making this conversion that we will learn later

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 relational logical arithmetic ! not

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

Empty Statements & Other Oddities The empty statement is written as a lone semicolon or a pair of braces Examples: ;// an empty statement {} // Empty block statement a + b + c;// legal, no useful work done

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

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