SlideShare a Scribd company logo
1 of 31
Operators and Decision-Making Constructs

Objectives
In this lesson, you will learn to:
 Use the following operators:
     Arithmetic
     Assignment
     Unary
     Comparison
     Logical
 Use decision-making constructs
     if…else constructs
     switch…case constructs
©NIIT                                OOPS/Lesson 4/Slide 1 of 31
Operators and Decision-Making Constructs

Objectives (Contd.)
 Use loop constructs
     while loop
     do…while loop
     for loop
 Scope of variables




©NIIT                        OOPS/Lesson 4/Slide 2 of 31
Operators and Decision-Making Constructs

Types of Operators
 Arithmetic operators
 Assignment operators
 Unary operators
 Comparison operators
 Logical operators
 Conditional operators




©NIIT                        OOPS/Lesson 4/Slide 3 of 31
Operators and Decision-Making Constructs

Arithmetic Operators
 Are used to perform arithmetic operations
 Are used in an order according to the
  precedence rules



            Type                 Operators    Associativity

            Value construction   ()           Innermost to outermost

            Multiplicative       *    /   %   Left to right

            Additive             +    -       Left to right




©NIIT                                                     OOPS/Lesson 4/Slide 4 of 31
Operators and Decision-Making Constructs

Arithmetic Assignment Operators
 Are used to assign the value of the right operand to
  the left
 Are as follows: =, +=, -=, /=, *=, %=




©NIIT                                     OOPS/Lesson 4/Slide 5 of 31
Operators and Decision-Making Constructs

Unary Operators
 Operate on one operand
 Are of two types:
     Increment operator (++)
     Decrement operator (--)




©NIIT                           OOPS/Lesson 4/Slide 6 of 31
Operators and Decision-Making Constructs

Comparison Operators
 Are also called relational operators
 Are used to compare two values
 Evaluate to true or false




©NIIT                                    OOPS/Lesson 4/Slide 7 of 31
Operators and Decision-Making Constructs

Comparison Operators (Contd.)

        Operator Description                            Example Explanation


        ==       Evaluates whether or not the           x == y   Returns true if the values are equal and false
                 operands are equal.                             otherwise
                 Evaluates whether or not the           x != y   Returns true if the values are not equal and
        !=
                 operands are not equal                          false otherwise

                 Evaluates whether or not the left      x  y
                                                                 Returns true if x is greater than y and false
                operand is greater than the right
                                                                 otherwise
                 operand
                 Evaluates whether or not the left      x  y
                                                                Returns true if x is less than y and false
                 operand is less than the right
                                                                 otherwise
                 operand
                 Evaluates whether or not the left      x = y
                                                                 Returns true if x is greater than or equal to y
        =       operand is greater than or equal to
                                                                 and false otherwise
                 the right operand
                 Evaluates whether or not the left      x = y
                                                                 Returns true if x is less than or equal to y and
        =       operand is less than or equal to the
                                                                 false otherwise
                 right operand




©NIIT                                                                            OOPS/Lesson 4/Slide 8 of 31
Operators and Decision-Making Constructs

Logical Operators
 Are used to combine two or more expressions
 Are of three types:
     AND ()
     OR (||)
     NOT (!)




©NIIT                             OOPS/Lesson 4/Slide 9 of 31
Operators and Decision-Making Constructs

Conditional Constructs
 Control the flow of a program
 Allow selective execution of statements
 Use comparison operators for evaluating conditions
 Are of two types:
     The if…else construct
     The switch…case construct




©NIIT                               OOPS/Lesson 4/Slide 10 of 31
Operators and Decision-Making Constructs

The if…else Construct
In an if…else block of statements:
 Condition is evaluated first
 If condition is true, statements in the immediate block
  are executed
 If condition is false, statements in the else block are
  executed




©NIIT                                OOPS/Lesson 4/Slide 11 of 31
Operators and Decision-Making Constructs

The if…else Construct (Contd.)
Syntax:
  if (expression)
  {
  statements;
  }
  else
  {
  statements;
  }

©NIIT                            OOPS/Lesson 4/Slide 12 of 31
Operators and Decision-Making Constructs

Just a Minute…
Write a construct that assigns grades to students based
on their marks. Students who have scored marks
between 75 and 100 are to be given grade ‘A’, those who
have scored between 50 and 75 are to be given grade
‘B’, and the rest of them should be given grade ‘C’.




©NIIT                              OOPS/Lesson 4/Slide 13 of 31
Operators and Decision-Making Constructs

The switch…case Construct
 Is used when there are multiple values for a variable
 Evaluates condition-variable of the switch statement
  and compares with each case constant
 Requires a break statement to exit from its body
 Uses default keyword for associating any other
  statements other than mentioned in the case constant




©NIIT                                OOPS/Lesson 4/Slide 14 of 31
Operators and Decision-Making Constructs

Loop Constructs
 Cause a section of a program to be repeated a certain
  number of times
 Are of three types:
     while loop
     do…while loop
     for loop




©NIIT                              OOPS/Lesson 4/Slide 15 of 31
Operators and Decision-Making Constructs

The while Loop
 Continues until the evaluating condition becomes
  false
Syntax:
  while (expression)
  {
  statements;
  }
 Requires the continue statement to return the
  control to the beginning of while loop skipping any
  other statements after the continue keyword

©NIIT                                OOPS/Lesson 4/Slide 16 of 31
Operators and Decision-Making Constructs

Just a Minute...
Write a function to display the sum of all numbers
between 1 and 100.




©NIIT                                OOPS/Lesson 4/Slide 17 of 31
Operators and Decision-Making Constructs

The do...while Loop
 Continues until the evaluating condition becomes
  false
 Executes the body of the loop at least once
Syntax:
  do
  {
  statements;
  } while(boolean_expr);



©NIIT                               OOPS/Lesson 4/Slide 18 of 31
Operators and Decision-Making Constructs

The for Loop
 Provides a compact way of specifying statements that
  control the repetition of the steps within the loop
 Contains three expressions:
     The initialization expression
     The test expression
     The increment/decrement expression




©NIIT                                 OOPS/Lesson 4/Slide 19 of 31
Operators and Decision-Making Constructs

The for Loop (Contd.)
Syntax:
  for( initialization_expr; test_expr; change_expr)
  {
          statements;

  }




©NIIT                                OOPS/Lesson 4/Slide 20 of 31
Operators and Decision-Making Constructs

The break and continue statement
 The break statement is used to exit a loop before the
  loop condition is re-evaluated after iteration
 The continue statement is used to skip all the
  subsequent instructions and take the control back to
  the loop




©NIIT                               OOPS/Lesson 4/Slide 21 of 31
Operators and Decision-Making Constructs

Problem Statement 4.D.1
 Write a program that will reverse an accepted string
 and copy it into another string.




©NIIT                               OOPS/Lesson 4/Slide 22 of 31
Operators and Decision-Making Constructs

Problem Statement 4.D.2
Write a program that displays the amount outstanding for
all customers. The amount outstanding should be
displayed in an ascending order.
The amount outstanding is represented as an array of
float values:
float amounts[10] =
{200.5,323,0,100.7,314,523,256,10.90,
    553.90,0};




©NIIT                               OOPS/Lesson 4/Slide 23 of 31
Operators and Decision-Making Constructs

Problem Statement 4.P.1
Write a program to accept the salaries of 10 employees
from the user and displays them in descending order for
all the employees. If the user enters zero, the program
should display the message “The amount should be
greater than zero” and accept the value again.




©NIIT                               OOPS/Lesson 4/Slide 24 of 31
Operators and Decision-Making Constructs

The Scope of a Variable
Falls under three heads:
     File scope
     Local scope
     Class scope




©NIIT                       OOPS/Lesson 4/Slide 25 of 31
Operators and Decision-Making Constructs

File Scope
 Is considered to be the outermost scope
 Variables are accessible throughout the program file
 Are called global variables




©NIIT                               OOPS/Lesson 4/Slide 26 of 31
Operators and Decision-Making Constructs

Local Scope
 Is defined as being limited to the braces of a function
  or a control structure like for, while, and if
 Are called local variables




©NIIT                                 OOPS/Lesson 4/Slide 27 of 31
Operators and Decision-Making Constructs

Class Scope
 Variables are accessible only within the class
 Variables have the flexibility of being accessed
  outside the class by declaring them as public




©NIIT                                OOPS/Lesson 4/Slide 28 of 31
Operators and Decision-Making Constructs

Summary
In this lesson, you learned that:
 Operators are used to compute and compare values
  and test multiple conditions
 You use arithmetic operators to perform arithmetic
  operations, such as addition, subtraction,
  multiplication, and division
 You can also use arithmetic assignment operators to
  perform arithmetic operations
 The unary operators, such as the increment and
  decrement operators operate on one operand
 Comparison operators, which are also called relational
operators, are used to compare two values

©NIIT                               OOPS/Lesson 4/Slide 29 of 31
Operators and Decision-Making Constructs

Summary (Contd.)
 Logical operators are used to combine two or more
  expressions
 Conditional constructs are used to allow the selective
  execution of statements. The conditional constructs in
  C++ are:
    if...else
     switch...case
 Looping constructs are used when you want a section
  of a program to be repeated a certain number of
  times. C++ offers the following looping constructs:
     while
     do...while
     for
©NIIT                               OOPS/Lesson 4/Slide 30 of 31
Operators and Decision-Making Constructs

Summary (Contd.)
 The break and continue statements are used to
  control the program flow within a loop
The scope of a variable specifies its accessibility
 C++ features three types of scopes: file, class, and
  local scope




©NIIT                                OOPS/Lesson 4/Slide 31 of 31

More Related Content

What's hot

Type conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingType conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingDhrumil Panchal
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions NotesProf Ansari
 
Project in TLE
Project in TLEProject in TLE
Project in TLEPGT_13
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsTech
 
Control statements and functions in c
Control statements and functions in cControl statements and functions in c
Control statements and functions in cvampugani
 
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlENGWAU TONNY
 
Report Group 4 Constants and Variables
Report Group 4 Constants and VariablesReport Group 4 Constants and Variables
Report Group 4 Constants and VariablesGenard Briane Ancero
 
control statements of clangauge (ii unit)
control statements of clangauge (ii unit)control statements of clangauge (ii unit)
control statements of clangauge (ii unit)Prashant Sharma
 
Linear regression in machine learning
Linear regression in machine learningLinear regression in machine learning
Linear regression in machine learningShajun Nisha
 
Cse lecture-4.1-c operators and expression
Cse lecture-4.1-c operators and expressionCse lecture-4.1-c operators and expression
Cse lecture-4.1-c operators and expressionFarshidKhan
 
Selection statements
Selection statementsSelection statements
Selection statementsHarsh Dabas
 

What's hot (20)

Type conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingType conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programming
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
Operator of C language
Operator of C languageOperator of C language
Operator of C language
 
C operator and expression
C operator and expressionC operator and expression
C operator and expression
 
Decision control
Decision controlDecision control
Decision control
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
 
Project in TLE
Project in TLEProject in TLE
Project in TLE
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 
Basics of c++
Basics of c++ Basics of c++
Basics of c++
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Control statements and functions in c
Control statements and functions in cControl statements and functions in c
Control statements and functions in c
 
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
 
Report Group 4 Constants and Variables
Report Group 4 Constants and VariablesReport Group 4 Constants and Variables
Report Group 4 Constants and Variables
 
control statements of clangauge (ii unit)
control statements of clangauge (ii unit)control statements of clangauge (ii unit)
control statements of clangauge (ii unit)
 
Linear regression in machine learning
Linear regression in machine learningLinear regression in machine learning
Linear regression in machine learning
 
9 cm604.10
9 cm604.109 cm604.10
9 cm604.10
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
Cse lecture-4.1-c operators and expression
Cse lecture-4.1-c operators and expressionCse lecture-4.1-c operators and expression
Cse lecture-4.1-c operators and expression
 
Selection statements
Selection statementsSelection statements
Selection statements
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
 

Viewers also liked

Viewers also liked (11)

Cs1123 6 loops
Cs1123 6 loopsCs1123 6 loops
Cs1123 6 loops
 
Datatype introduction- JAVA
Datatype introduction- JAVADatatype introduction- JAVA
Datatype introduction- JAVA
 
6 java - loop
6  java - loop6  java - loop
6 java - loop
 
Java Datatypes
Java DatatypesJava Datatypes
Java Datatypes
 
Chapter 1. java programming language overview
Chapter 1. java programming language overviewChapter 1. java programming language overview
Chapter 1. java programming language overview
 
1 Introduction To Java Technology
1 Introduction To Java Technology 1 Introduction To Java Technology
1 Introduction To Java Technology
 
Basic Computer Skills Seminar
Basic Computer Skills Seminar Basic Computer Skills Seminar
Basic Computer Skills Seminar
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programming
 
Java packages
Java packagesJava packages
Java packages
 
Java essentials for hadoop
Java essentials for hadoopJava essentials for hadoop
Java essentials for hadoop
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 

Similar to Aae oop xp_04

Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cSowmya Jyothi
 
C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...mshakeel44514451
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c languageshhanks
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.netJaya Kumari
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3rohassanie
 
lecture4 pgdca.pptx
lecture4 pgdca.pptxlecture4 pgdca.pptx
lecture4 pgdca.pptxclassall
 
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdf
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdfBasic_C++ Notes with problema from Preethi arora and suneetha arora.pdf
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdfComputer Programmer
 
Variable, constant, operators and control statement
Variable, constant, operators and control statementVariable, constant, operators and control statement
Variable, constant, operators and control statementEyelean xilef
 
Variable, constant, operators and control statement
Variable, constant, operators and control statementVariable, constant, operators and control statement
Variable, constant, operators and control statementEyelean xilef
 
03 Operators and expressions
03 Operators and expressions03 Operators and expressions
03 Operators and expressionsmaznabili
 
4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.pptRithwikRanjan
 

Similar to Aae oop xp_04 (20)

Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...
 
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c language
 
Operators
OperatorsOperators
Operators
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.net
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
Icom4015 lecture4-f17
Icom4015 lecture4-f17Icom4015 lecture4-f17
Icom4015 lecture4-f17
 
lecture4 pgdca.pptx
lecture4 pgdca.pptxlecture4 pgdca.pptx
lecture4 pgdca.pptx
 
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdf
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdfBasic_C++ Notes with problema from Preethi arora and suneetha arora.pdf
Basic_C++ Notes with problema from Preethi arora and suneetha arora.pdf
 
LOOPS AND DECISIONS
LOOPS AND DECISIONSLOOPS AND DECISIONS
LOOPS AND DECISIONS
 
Java script session 4
Java script session 4Java script session 4
Java script session 4
 
slides03.ppt
slides03.pptslides03.ppt
slides03.ppt
 
Variable, constant, operators and control statement
Variable, constant, operators and control statementVariable, constant, operators and control statement
Variable, constant, operators and control statement
 
Variable, constant, operators and control statement
Variable, constant, operators and control statementVariable, constant, operators and control statement
Variable, constant, operators and control statement
 
03 Operators and expressions
03 Operators and expressions03 Operators and expressions
03 Operators and expressions
 
MODULE_2_Operators.pptx
MODULE_2_Operators.pptxMODULE_2_Operators.pptx
MODULE_2_Operators.pptx
 
4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt
 

More from Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Recently uploaded

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 

Recently uploaded (20)

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 

Aae oop xp_04

  • 1. Operators and Decision-Making Constructs Objectives In this lesson, you will learn to: Use the following operators: Arithmetic Assignment Unary Comparison Logical Use decision-making constructs if…else constructs switch…case constructs ©NIIT OOPS/Lesson 4/Slide 1 of 31
  • 2. Operators and Decision-Making Constructs Objectives (Contd.) Use loop constructs while loop do…while loop for loop Scope of variables ©NIIT OOPS/Lesson 4/Slide 2 of 31
  • 3. Operators and Decision-Making Constructs Types of Operators Arithmetic operators Assignment operators Unary operators Comparison operators Logical operators Conditional operators ©NIIT OOPS/Lesson 4/Slide 3 of 31
  • 4. Operators and Decision-Making Constructs Arithmetic Operators Are used to perform arithmetic operations Are used in an order according to the precedence rules Type Operators Associativity Value construction () Innermost to outermost Multiplicative * / % Left to right Additive + - Left to right ©NIIT OOPS/Lesson 4/Slide 4 of 31
  • 5. Operators and Decision-Making Constructs Arithmetic Assignment Operators Are used to assign the value of the right operand to the left Are as follows: =, +=, -=, /=, *=, %= ©NIIT OOPS/Lesson 4/Slide 5 of 31
  • 6. Operators and Decision-Making Constructs Unary Operators Operate on one operand Are of two types: Increment operator (++) Decrement operator (--) ©NIIT OOPS/Lesson 4/Slide 6 of 31
  • 7. Operators and Decision-Making Constructs Comparison Operators Are also called relational operators Are used to compare two values Evaluate to true or false ©NIIT OOPS/Lesson 4/Slide 7 of 31
  • 8. Operators and Decision-Making Constructs Comparison Operators (Contd.) Operator Description Example Explanation == Evaluates whether or not the x == y Returns true if the values are equal and false operands are equal. otherwise Evaluates whether or not the x != y Returns true if the values are not equal and != operands are not equal false otherwise Evaluates whether or not the left x y Returns true if x is greater than y and false operand is greater than the right otherwise operand Evaluates whether or not the left x y Returns true if x is less than y and false operand is less than the right otherwise operand Evaluates whether or not the left x = y Returns true if x is greater than or equal to y = operand is greater than or equal to and false otherwise the right operand Evaluates whether or not the left x = y Returns true if x is less than or equal to y and = operand is less than or equal to the false otherwise right operand ©NIIT OOPS/Lesson 4/Slide 8 of 31
  • 9. Operators and Decision-Making Constructs Logical Operators Are used to combine two or more expressions Are of three types: AND () OR (||) NOT (!) ©NIIT OOPS/Lesson 4/Slide 9 of 31
  • 10. Operators and Decision-Making Constructs Conditional Constructs Control the flow of a program Allow selective execution of statements Use comparison operators for evaluating conditions Are of two types: The if…else construct The switch…case construct ©NIIT OOPS/Lesson 4/Slide 10 of 31
  • 11. Operators and Decision-Making Constructs The if…else Construct In an if…else block of statements: Condition is evaluated first If condition is true, statements in the immediate block are executed If condition is false, statements in the else block are executed ©NIIT OOPS/Lesson 4/Slide 11 of 31
  • 12. Operators and Decision-Making Constructs The if…else Construct (Contd.) Syntax: if (expression) { statements; } else { statements; } ©NIIT OOPS/Lesson 4/Slide 12 of 31
  • 13. Operators and Decision-Making Constructs Just a Minute… Write a construct that assigns grades to students based on their marks. Students who have scored marks between 75 and 100 are to be given grade ‘A’, those who have scored between 50 and 75 are to be given grade ‘B’, and the rest of them should be given grade ‘C’. ©NIIT OOPS/Lesson 4/Slide 13 of 31
  • 14. Operators and Decision-Making Constructs The switch…case Construct Is used when there are multiple values for a variable Evaluates condition-variable of the switch statement and compares with each case constant Requires a break statement to exit from its body Uses default keyword for associating any other statements other than mentioned in the case constant ©NIIT OOPS/Lesson 4/Slide 14 of 31
  • 15. Operators and Decision-Making Constructs Loop Constructs Cause a section of a program to be repeated a certain number of times Are of three types: while loop do…while loop for loop ©NIIT OOPS/Lesson 4/Slide 15 of 31
  • 16. Operators and Decision-Making Constructs The while Loop Continues until the evaluating condition becomes false Syntax: while (expression) { statements; } Requires the continue statement to return the control to the beginning of while loop skipping any other statements after the continue keyword ©NIIT OOPS/Lesson 4/Slide 16 of 31
  • 17. Operators and Decision-Making Constructs Just a Minute... Write a function to display the sum of all numbers between 1 and 100. ©NIIT OOPS/Lesson 4/Slide 17 of 31
  • 18. Operators and Decision-Making Constructs The do...while Loop Continues until the evaluating condition becomes false Executes the body of the loop at least once Syntax: do { statements; } while(boolean_expr); ©NIIT OOPS/Lesson 4/Slide 18 of 31
  • 19. Operators and Decision-Making Constructs The for Loop Provides a compact way of specifying statements that control the repetition of the steps within the loop Contains three expressions: The initialization expression The test expression The increment/decrement expression ©NIIT OOPS/Lesson 4/Slide 19 of 31
  • 20. Operators and Decision-Making Constructs The for Loop (Contd.) Syntax: for( initialization_expr; test_expr; change_expr) { statements; } ©NIIT OOPS/Lesson 4/Slide 20 of 31
  • 21. Operators and Decision-Making Constructs The break and continue statement The break statement is used to exit a loop before the loop condition is re-evaluated after iteration The continue statement is used to skip all the subsequent instructions and take the control back to the loop ©NIIT OOPS/Lesson 4/Slide 21 of 31
  • 22. Operators and Decision-Making Constructs Problem Statement 4.D.1 Write a program that will reverse an accepted string and copy it into another string. ©NIIT OOPS/Lesson 4/Slide 22 of 31
  • 23. Operators and Decision-Making Constructs Problem Statement 4.D.2 Write a program that displays the amount outstanding for all customers. The amount outstanding should be displayed in an ascending order. The amount outstanding is represented as an array of float values: float amounts[10] = {200.5,323,0,100.7,314,523,256,10.90, 553.90,0}; ©NIIT OOPS/Lesson 4/Slide 23 of 31
  • 24. Operators and Decision-Making Constructs Problem Statement 4.P.1 Write a program to accept the salaries of 10 employees from the user and displays them in descending order for all the employees. If the user enters zero, the program should display the message “The amount should be greater than zero” and accept the value again. ©NIIT OOPS/Lesson 4/Slide 24 of 31
  • 25. Operators and Decision-Making Constructs The Scope of a Variable Falls under three heads: File scope Local scope Class scope ©NIIT OOPS/Lesson 4/Slide 25 of 31
  • 26. Operators and Decision-Making Constructs File Scope Is considered to be the outermost scope Variables are accessible throughout the program file Are called global variables ©NIIT OOPS/Lesson 4/Slide 26 of 31
  • 27. Operators and Decision-Making Constructs Local Scope Is defined as being limited to the braces of a function or a control structure like for, while, and if Are called local variables ©NIIT OOPS/Lesson 4/Slide 27 of 31
  • 28. Operators and Decision-Making Constructs Class Scope Variables are accessible only within the class Variables have the flexibility of being accessed outside the class by declaring them as public ©NIIT OOPS/Lesson 4/Slide 28 of 31
  • 29. Operators and Decision-Making Constructs Summary In this lesson, you learned that: Operators are used to compute and compare values and test multiple conditions You use arithmetic operators to perform arithmetic operations, such as addition, subtraction, multiplication, and division You can also use arithmetic assignment operators to perform arithmetic operations The unary operators, such as the increment and decrement operators operate on one operand Comparison operators, which are also called relational operators, are used to compare two values ©NIIT OOPS/Lesson 4/Slide 29 of 31
  • 30. Operators and Decision-Making Constructs Summary (Contd.) Logical operators are used to combine two or more expressions Conditional constructs are used to allow the selective execution of statements. The conditional constructs in C++ are: if...else switch...case Looping constructs are used when you want a section of a program to be repeated a certain number of times. C++ offers the following looping constructs: while do...while for ©NIIT OOPS/Lesson 4/Slide 30 of 31
  • 31. Operators and Decision-Making Constructs Summary (Contd.) The break and continue statements are used to control the program flow within a loop The scope of a variable specifies its accessibility C++ features three types of scopes: file, class, and local scope ©NIIT OOPS/Lesson 4/Slide 31 of 31