Lesson - 7. Operators There are three types of operators: Arithmetic Operators Relational and Equality Operators Logical Operators.

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

LECTURE 3: BASIC C OPERATORS. Objectives  In this chapter, you will learn about:  Arithmetic operators Unary operators Binary operators  Assignment.
Department of Computer Science. Definition “An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations.
Conditionals – if - else Dr. Sajib Datta
Flow of Control (1) : Logic Clark Savage Turner, J.D., Ph.D. Some lecture slides have been adapted from those developed.
Chapter 2: Java Fundamentals Operators. Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR Page 2 Content Group of Operators Arithmetic Operators Assignment.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
Primitive Types CSE 115 Spring 2006 April 3 &
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.
Boolean Expressions and If Flow of Control / Conditional Statements The if Statement Logical Operators The else Clause Block statements Nested if statements.
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
Chapter 4: Basic C Operators
Chapter 4: Operators Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills /1436.
Exercises A-Declare a variable of double type with initial value=0.0; B- Declare a constant of String type with initial value=“Good” C- Declare a variable.
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
2440: 211 Interactive Web Programming Expressions & Operators.
CSE1301 Computer Programming Lecture 5: C Primitives 2 Corrections.
LESSON 6 – Arithmetic Operators
CSCI 1100/1202 January 28, The switch Statement The switch statement provides another means to decide which statement to execute next The switch.
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.
C Programming Lecture 6 : Operators Lecture notes : courtesy of Ohio Supercomputing Center, and Prof. Woo and Prof. Chang.
C++ Basics Tutorial 6 Operators. What are going to see today? Assignment operator(=) Arithmetic operators(+,-,*,/,%) Compound assignment(+=,-=,*=……..)
AEEE 195 – Repetition Structures: Part B Spring semester 2011.
Operators. Today’s Learning Goals … Understand the purpose of JavaScript operators Explore the mathematical operators Find out about the assignment operators.
C Operators. CONTENTS C OPERATORS TYPES OF OPERATOR UNARY BINARY TERNARY ARITHMATIC RELATIONAL LOGICAL.
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.
Lesson - 5. Introduction While programming, we usually need to decide the path of the program flow according to the parameters and conditions. Actually.
CHAPTER 1.3 THE OPERATORS Dr. Shady Yehia Elmashad.
1 Operators and Expressions. Expressions Combination of Operators and Operands Example 2 * y + 5 Operands Operators.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
1 Expressions. 2 Variables and constants linked with operators  Arithmetic expressions Uses arithmetic operators Can evaluate to any value  Logical.
© 2006 Pearson Education 1 Obj: to use assignment operators HW: Prelab Exercises 2 Quiz 3.1 – 3.4 in two class days  Do Now: 1.Read p.144 – 145 (3.4 “more.
Principles of Programming Chapter 4: Basic C Operators  In this chapter, you will learn about:  Arithmetic operators  Unary operators  Binary operators.
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.
1 Program Development  The creation of software involves four basic activities: establishing the requirements creating a design implementing the code.
Operators & Expressions
Doing math In java.
CSEB 114: PRINCIPLE OF PROGRAMMING Chapter 4: Basic C Operators.
OperatorstMyn1 Operators An operator is something that you feed with one or more values (or expressions, in programming jargon) which yields another value.
 Arithmetic Operator :  Increment / Decrement Operator :  Assignment Operator :  Comparision Operator :  Logical Operator :  Ternary Operator : 
1 b Boolean expressions b truth tables b conditional operator b switch statement b repetition statements: whilewhile do/whiledo/while forfor Lecture 3.
Operators.
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.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
Principles of Programming - NI July Chapter 4: Basic C Operators In this chapter, you will learn about: Assignment operators Arithmetic operators.
Operators & Expressions
Operators And Expressions
University of Central Florida COP 3330 Object Oriented Programming
Solving Equations with the Variable on Each Side
Operators Operators are symbols such as + (addition), - (subtraction), and * (multiplication). Operators do something with values. $foo = 25; $foo – 15;
Addition/ Subtraction
University of Central Florida COP 3330 Object Oriented Programming
Relational Operations
Operators and Expressions
With Assignment Operator
C Operators, Operands, Expressions & Statements
3 Control Statements:.
Introduction to Programming – 4 Operators
Expressions.
Logic of an if statement
Lecture 5 Binary Operation Boolean Logic. Binary Operations Addition Subtraction Multiplication Division.
OPERATORS AND EXPRESSIONS IN C++
Multiply and divide Expressions
Chap 7. Advanced Control Statements in Java
Operator and Expression
Presentation transcript:

Lesson - 7

Operators There are three types of operators: Arithmetic Operators Relational and Equality Operators Logical Operators

Arithmetic Operators Main operators used in C++ are: OperationOperatorExample Addition+5+4 = 9 Subtraction-5-4=1, 4-5=-1 Multiplication*5*4=20 Integer Division/15/3=5, 12/5=2 Modulus%15%3=0, 12%5=2, 4%5=4

C++ Relational and Equality Operators C++ Relational and Equality Operators are: OperationOperatorExample Greater>8>7, b>a, Num1>Num2, Char1>Char2 Greater or Equal>=15>= 14, c>=b Smaller<7<8, d<e Smaller or Equal<=Num1<=Num2, Char1<=Char2 Equal==Num1==Num2, strg1==strg2 Not Equal!=Num1!=Num2, Variable1!=Variable2

Logical Operators Logical operators simplify nested if and if/else structures. They combine multiple logical expressions and return a single result (True or False). There are three logical operators in C++: ! (Not) && (And) || (Or)

! Logical Not Operator ! Logical Not Operator has only one operand (unary operator) and returns the opposite of it. Not Operator gives true if the operand is false, and gives false if the operand is true. For example: !(5 > 7) //evaluates to true. !true //evaluates to false. X!X The truth table of the Not Operator ( ! )

&& Logical And Operator && Logical And Operator has two operands (binary operator). It returns true only if both operands are true, and returns false otherwise. So we may need this operator when we have to perform a task if two conditions are fulfilled at the same time. For example we want to determine if a given integer (num) is divisible by 3 and 7. if ((num % 3 == 0) && (num % 7 == 0)) cout<<"It is divisible by 3 and 7"; XYX&&Y The truth table of the And Operator ( && )

|| Logical Or Operator || Logical Or Operator has two operands. It returns false if both operands are false, and returns true otherwise. It can be used in a case if at least one of two conditions has to be true to perform a task. For example we want to check if a number is divisible by 3 or 7. if ((num % 3 == 0) || (num % 7 == 0)) cout<<"It is divisible by 3 or 7"; XYX||Y The truth table of the Or Operator (||)

Increment and Decrement Operators C++ provides unary increment (++) and decrement (--) operators. Both operators can be used after (a++, post-increment) or before (++a, pre-increment) their operands. If the variable 'a' needs to be incremented by 1, "a++", "a=a+1", or "a+=1" can be used. If the variable 'a' needs to be decremented by 1, "a--", "a=a-1", or "a-=1" can be used.

Thank you for your listening!