SlideShare a Scribd company logo
Representing the Logic of Programs with Conditions


 Objectives
 In this lesson, you will learn about:
  Data and data types
  Using operators
  Representing decisions in a flowchart




  ©NIIT                                  PLT/Lesson 2/Slide 1 of 33
Representing the Logic of Programs with Conditions

 Variables and Constants
 Flowchart to display the sum of two numbers
                           Start



                       Accept the
                       First Number



                      Accept the
                      Second Number



                   Add the two Numbers
                   and Store the Result



                    Display the Result



                           Stop

  ©NIIT                                   PLT/Lesson 2/Slide 2 of 33
Representing the Logic of Programs with Conditions


 Variables and Constants (Contd.)
  The internal memory consists of different locations in

     which data is stored
  A computer needs to identify the memory locations to
   be able to retrieve values from or store values in them
  The value of a variable changes each time the set of
   instructions is executed
  The values stored in the variables are known as
   constants




  ©NIIT                                 PLT/Lesson 2/Slide 3 of 33
Representing the Logic of Programs with Conditions


 Variables and Constants (Contd.)


                       Constants




                10        15       25


               nNum1     nNum2     nSum




                       Variables




  ©NIIT                                 PLT/Lesson 2/Slide 4 of 33
Representing the Logic of Programs with Conditions

 Variables and Constants (Contd.)
 Flowchart to display the sum of two numbers using
 variables.                Start




                      Accept nNum1




                      Accept nNum2




                   nSum = nNum1 + nNum2



                      Display nSum



                           Stop


  ©NIIT                                   PLT/Lesson 2/Slide 5 of 33
Representing the Logic of Programs with Conditions


 Just a Minute…
 Identify the variable and constant data in the following
 situation:
 Each day, the courier service delivers some letters. The
 number of letters is different each day. Regardless of the
 number of letters delivered by the courier service, they
 are paid a carrying charge of $5.
 Variable:
 Constant:




  ©NIIT                                  PLT/Lesson 2/Slide 6 of 33
Representing the Logic of Programs with Conditions


 Just a Minute…
 Identify the variables and constants from the list
 given below:
 a) Age
 b) Address
 c) 21
 d) “10, Kingsway Camp”
 e) “Henri”
 f) Name
 g) “185”

  ©NIIT                                PLT/Lesson 2/Slide 7 of 33
Representing the Logic of Programs with Conditions


 Data Types
  Numeric
       Numeric variables can contain only numbers
       These variables can be used in arithmetic
        operations
  Character
       Character variables can contain any combination
        of letters, numbers, and special characters
       These variables cannot be used for calculation




  ©NIIT                                 PLT/Lesson 2/Slide 8 of 33
Representing the Logic of Programs with Conditions


 Data Types
  Declaring Variables
                             Start


                         numeric nNum1,
                          nNum2, nSum



                         Accept nNum1



                         Accept nNum2



                     nSum = nNum1 + nNum2



                         Display nSum



                              Stop

  ©NIIT                                     PLT/Lesson 2/Slide 9 of 33
Representing the Logic of Programs with Conditions


 Data Types
  Variable Naming Conventions
          ® Thefirst letter of the variable may indicate the
           data type used
          ® Thevariable name should clearly describe its
           purpose
          ® In
             case of multiple words, the first letter of each
           word could be capitalized for better readability




  ©NIIT                                   PLT/Lesson 2/Slide 10 of 33
Representing the Logic of Programs with Conditions


 Using Operators
  Operators are tools for some predefined operations
  The operators that are used in flowcharts are:
       Arithmetic operators
       Relational operators
       Logical operators




  ©NIIT                                PLT/Lesson 2/Slide 11 of 33
Representing the Logic of Programs with Conditions


 Using Operators
  Arithmetic operators
       Arithmetic operators are used to perform arithmetic
        calculations
       The symbols that represent arithmetic operations
        are called arithmetic operators (*, /, +, -, %)
  Relational operators
       Relational operators are used to test the
        relationship between two variables or the
        relationship between a variable and a constant
       There are six relational operators (=,,,!=,=,=)

  ©NIIT                                  PLT/Lesson 2/Slide 12 of 33
Representing the Logic of Programs with Conditions


 Using Operators
  Logical operators
       Logical operators (AND, OR, NOT) are used to
        combine expressions containing relational
        operators
          ® nNum1   = 7 AND nNum2  5
          ® nNum1   = 7 OR nNum2  5
          ® NOT   nNum2 = 5
       Precedence of the execution of logical operators
        are NOT, AND, and OR.


  ©NIIT                                 PLT/Lesson 2/Slide 13 of 33
Representing the Logic of Programs with Conditions


 Just a Minute…
 Draw a flowchart to accept item name, price, and
 quantity. You need to calculate value as the product of
 price and quantity, and display the calculated value and
 the item name using variables.




  ©NIIT                                PLT/Lesson 2/Slide 14 of 33
Representing the Logic of Programs with Conditions


 Representing Decisions in a Flowchart
  Many problems require decisions to be made
  All decisions may or may not state an action to be
   taken if the condition is false




  ©NIIT                                PLT/Lesson 2/Slide 15 of 33
Representing the Logic of Programs with Conditions


 Representing Decisions in a Flowchart
 Flowchart Segment to Compare Two Numbers and
 Check for Equality


                  Is nNum1 =    No
                    nNum2 ?


                        Yes


                 Display “The        Display “The
                 numbers are         numbers are
                    equal”            not equal”




  ©NIIT                                     PLT/Lesson 2/Slide 16 of 33
Representing the Logic of Programs with Conditions

 Example
 Accept two numbers and print the larger of the two
 numbers.
                            Start


                        numeric nNum1,
                           nNum2



                        Accept nNum1




                        Accept nNum2



                             A




  ©NIIT                                  PLT/Lesson 2/Slide 17 of 33
Representing the Logic of Programs with Conditions

 Example (Contd.)

                    A



                    Is      Yes     Display “ The
               nNum1=nNum2?       numbers are equal”


                        No

                    Is      Yes
               nNum1nNum2?       Display nNum1


                        No

               Display nNum2



                    Stop




  ©NIIT                                  PLT/Lesson 2/Slide 18 of 33
Representing the Logic of Programs with Conditions


 Example
 Print the value of nX only if the value of nX is greater
 than 10 and nX is an even number.
                            Start


                         numeric nX



                         Accept nX



                             Is
                                      No
                         nX10 AND
                          nX%2=0?

                              Yes

                         Display nX



                            Stop
  ©NIIT                                    PLT/Lesson 2/Slide 19 of 33
Representing the Logic of Programs with Conditions


 Example
 Accept the year and then determine whether the year is
 a leap year or not. A leap year is one that is divisible by
 4, other than a century year, such as 1900. A century
 year, which is divisible by 400, such as 2000, is also a
 leap year.
 To evaluate the given condition, we can interpret this as:
 If year is divisible by 4 AND not divisible by 100 OR
 divisible by 400, it is a leap year.




  ©NIIT                                  PLT/Lesson 2/Slide 20 of 33
Representing the Logic of Programs with Conditions


 Flowchart to Determine the Leap Year

                          Start


                     numeric nYear



                    Display “ Please
                       enter a year”



                     Accept nYear



                          A




  ©NIIT                                PLT/Lesson 2/Slide 21 of 33
Representing the Logic of Programs with Conditions

 Flowchart to Determine the Leap Year (Contd.)

                        A




                       Is
                nYear % 4=0 AND       No   Display “ This is
                (nYear % 100 !=0 OR
                                           not a leap year”
                 nYear % 400=0) ?




                            Yes
                 Display “This is
                   a leap year”


                       Stop




  ©NIIT                                     PLT/Lesson 2/Slide 22 of 33
Representing the Logic of Programs with Conditions


 Example
 To decide about the discount percentage on a TV, the
 sales person needs to check the type of TV. If the TV is
 Black and White [B], the discount will be 5 percent of the
 selling price. If the type of TV is colored[C], then he has
 to verify the size of TV screen. For 14 inches screen,
 discount is 8 percent of the selling price and for 21
 inches screen, the discount is 10 percent of the selling
 price.




  ©NIIT                                  PLT/Lesson 2/Slide 23 of 33
Representing the Logic of Programs with Conditions


 Flowchart to Calculate Discount
                    Start

          numeric nScreen, nDiscount
               character cType


               Accept cType
               Accept
               nScreen

                      Is        Yes
                  cType=‘B’?                 nDiscount=5% of SP

                        No

                      Is     Yes           Is        Yes
                                                                  nDiscount=8% of SP
                  cType=‘C’?           nScreen=14?


                       No                    No

                                           Is        Yes
                                                                  nDiscount=10% of SP
                                       nScreen=21?

                                             No

                    Stop
  ©NIIT                                                    PLT/Lesson 2/Slide 24 of 33
Representing the Logic of Programs with Conditions


 Problem Statement 2.P.1
 Study the given flowchart and answer the following
 questions.
 What will be output when:
  a) nNum=7
  b) nNum=3
  c) nNum=11




  ©NIIT                               PLT/Lesson 2/Slide 25 of 33
Representing the Logic of Programs with Conditions


  Problem Statement 2.P.1(Contd.)
                    Start


                numeric nNum


                Accept nNum



                     Is        Yes
                  nNum10?           Display “ GOOD”

                       No

                    Is         Yes
                  nNum5?             Display “OK”

                       No

               Display “REJECT”



                    Stop

  ©NIIT                                      PLT/Lesson 2/Slide 26 of 33
Representing the Logic of Programs with Conditions


  Problem Statement 2.P.2
  Study the flowchart and answer the following questions.
  What will be the output when:
  a) nX=150 and nY=75
  b) nX=90 and nY=50
  c) nX=40 and nY=80




  ©NIIT                                PLT/Lesson 2/Slide 27 of 33
Representing the Logic of Programs with Conditions


  Problem Statement 2.P.2 (Contd.)
              Start


          numeric nX, nY


            Accept nX


           Accept nY



               Is          Yes      Is        Yes
            nX  nY ?            nX  100 ?           Display “ GOOD”

                 No                    No

               Is          No
            nY  100 ?

                 Yes

            Display nY


              Stop

  ©NIIT                                         PLT/Lesson 2/Slide 28 of 33
Representing the Logic of Programs with Conditions


  Problem Statement 2.P.3
  Draw a flowchart to accept a number and then find out
  whether or not the number is divisible by 5.




  ©NIIT                                PLT/Lesson 2/Slide 29 of 33
Representing the Logic of Programs with Conditions


  Problem Statement 2.P.4
  Draw a flowchart to accept three numbers and display
  the largest number.




  ©NIIT                               PLT/Lesson 2/Slide 30 of 33
Representing the Logic of Programs with Conditions


  Problem Statement 2.P.5
  Candidates have to enter their age. The age cannot be
  negative. If a negative age is entered, an error message
  has to be displayed, otherwise the age is displayed.
  Represent the error checking logic for this situation
  using a flowchart.




  ©NIIT                                 PLT/Lesson 2/Slide 31 of 33
Representing the Logic of Programs with Conditions


 Summary
 In this lesson, you learned that:
  Data can be categorized as a constant or variable

  Data types can be:
       Numeric
       Character
  The operators are:
       Arithmetic
       Relational
       Logical

  ©NIIT                               PLT/Lesson 2/Slide 32 of 33
Representing the Logic of Programs with Conditions


 Summary (Contd.)
  Arithmetic operators are used to perform arithmetic
   calculations. The symbols that represents arithmetic
   operations are called arithmetic operators (*,/,+,-,%).
  Relational operators are used to test the relationship
   between two variables. The symbols that represent
   relational operations are called relational operators
   (,,=,!=).
  Logical operators (AND, OR, NOT) are used to
   combine expressions containing relational operators.
  The decision box is used to apply conditions by asking
   a question in a flowchart.

  ©NIIT                                 PLT/Lesson 2/Slide 33 of 33

More Related Content

What's hot

Iy2617051711
Iy2617051711Iy2617051711
Iy2617051711
IJERA Editor
 
PPT - Adaptive Quantitative Trading : An Imitative Deep Reinforcement Learnin...
PPT - Adaptive Quantitative Trading : An Imitative Deep Reinforcement Learnin...PPT - Adaptive Quantitative Trading : An Imitative Deep Reinforcement Learnin...
PPT - Adaptive Quantitative Trading : An Imitative Deep Reinforcement Learnin...
Jisang Yoon
 
Modeling interest rates and derivatives
Modeling interest rates and derivativesModeling interest rates and derivatives
Modeling interest rates and derivatives
Aiden Wu, FRM
 
Jörg Stelzer
Jörg StelzerJörg Stelzer
Jörg Stelzerbutest
 
2. reliability function
2. reliability function2. reliability function
2. reliability functionmadhurgujar
 
On the Semantics of Real-Time Domain Specific Modeling Languages
On the Semantics of Real-Time Domain Specific Modeling LanguagesOn the Semantics of Real-Time Domain Specific Modeling Languages
On the Semantics of Real-Time Domain Specific Modeling LanguagesJose E. Rivera
 

What's hot (8)

36
3636
36
 
Iy2617051711
Iy2617051711Iy2617051711
Iy2617051711
 
EEDC Programming Models
EEDC Programming ModelsEEDC Programming Models
EEDC Programming Models
 
PPT - Adaptive Quantitative Trading : An Imitative Deep Reinforcement Learnin...
PPT - Adaptive Quantitative Trading : An Imitative Deep Reinforcement Learnin...PPT - Adaptive Quantitative Trading : An Imitative Deep Reinforcement Learnin...
PPT - Adaptive Quantitative Trading : An Imitative Deep Reinforcement Learnin...
 
Modeling interest rates and derivatives
Modeling interest rates and derivativesModeling interest rates and derivatives
Modeling interest rates and derivatives
 
Jörg Stelzer
Jörg StelzerJörg Stelzer
Jörg Stelzer
 
2. reliability function
2. reliability function2. reliability function
2. reliability function
 
On the Semantics of Real-Time Domain Specific Modeling Languages
On the Semantics of Real-Time Domain Specific Modeling LanguagesOn the Semantics of Real-Time Domain Specific Modeling Languages
On the Semantics of Real-Time Domain Specific Modeling Languages
 

Similar to Sem1 plt xp_02

Algorithm review
Algorithm reviewAlgorithm review
Algorithm reviewchidabdu
 
Chapter 14
Chapter 14 Chapter 14
Chapter 14
Tuul Tuul
 
From_seq2seq_to_BERT
From_seq2seq_to_BERTFrom_seq2seq_to_BERT
From_seq2seq_to_BERT
Huali Zhao
 
Affine cascade models for term structure dynamics of sovereign yield curves
Affine cascade models for term structure dynamics of sovereign yield curvesAffine cascade models for term structure dynamics of sovereign yield curves
Affine cascade models for term structure dynamics of sovereign yield curves
LAURAMICHAELA
 
Lecture2a algorithm
Lecture2a algorithmLecture2a algorithm
Lecture2a algorithm
mbadhi barnabas
 
Banque de France's Workshop on Granularity: François Geerolf's slides, June 2...
Banque de France's Workshop on Granularity: François Geerolf's slides, June 2...Banque de France's Workshop on Granularity: François Geerolf's slides, June 2...
Banque de France's Workshop on Granularity: François Geerolf's slides, June 2...
Soledad Zignago
 
Divide&Conquer & Dynamic Programming
Divide&Conquer & Dynamic ProgrammingDivide&Conquer & Dynamic Programming
Divide&Conquer & Dynamic Programming
Guillaume Guérard
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV Syllabus
NANDINI SHARMA
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
Krishnan MuthuManickam
 
Attention is all you need (UPC Reading Group 2018, by Santi Pascual)
Attention is all you need (UPC Reading Group 2018, by Santi Pascual)Attention is all you need (UPC Reading Group 2018, by Santi Pascual)
Attention is all you need (UPC Reading Group 2018, by Santi Pascual)
Universitat Politècnica de Catalunya
 
Fair valuation of participating life insurance contracts with jump risk
Fair valuation of participating life insurance contracts with jump riskFair valuation of participating life insurance contracts with jump risk
Fair valuation of participating life insurance contracts with jump risk
Alex Kouam
 
Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...
Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...
Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...
Rafael Nogueras
 
Housing Price Models
Housing Price ModelsHousing Price Models
Housing Price Models
Gaetan Lion
 
Matlab 3
Matlab 3Matlab 3
Matlab 3asguna
 
01 - Analysis of Efficiency.pptx
01 - Analysis of Efficiency.pptx01 - Analysis of Efficiency.pptx
01 - Analysis of Efficiency.pptx
Ishtiaq Rasool Khan
 
Software Metrics
Software MetricsSoftware Metrics
Software Metrics
Ehsan Hessami
 
Chapter 2 Linear Programming for business (1).pptx
Chapter 2 Linear Programming for business (1).pptxChapter 2 Linear Programming for business (1).pptx
Chapter 2 Linear Programming for business (1).pptx
animutsileshe1
 
Biosight: Quantitative Methods for Policy Analysis - Introduction to GAMS, Li...
Biosight: Quantitative Methods for Policy Analysis - Introduction to GAMS, Li...Biosight: Quantitative Methods for Policy Analysis - Introduction to GAMS, Li...
Biosight: Quantitative Methods for Policy Analysis - Introduction to GAMS, Li...
IFPRI-EPTD
 
Measuring credit risk in a large banking system: econometric modeling and emp...
Measuring credit risk in a large banking system: econometric modeling and emp...Measuring credit risk in a large banking system: econometric modeling and emp...
Measuring credit risk in a large banking system: econometric modeling and emp...
SYRTO Project
 

Similar to Sem1 plt xp_02 (20)

Algorithm review
Algorithm reviewAlgorithm review
Algorithm review
 
Chapter 14
Chapter 14 Chapter 14
Chapter 14
 
From_seq2seq_to_BERT
From_seq2seq_to_BERTFrom_seq2seq_to_BERT
From_seq2seq_to_BERT
 
Algo complexity
Algo complexityAlgo complexity
Algo complexity
 
Affine cascade models for term structure dynamics of sovereign yield curves
Affine cascade models for term structure dynamics of sovereign yield curvesAffine cascade models for term structure dynamics of sovereign yield curves
Affine cascade models for term structure dynamics of sovereign yield curves
 
Lecture2a algorithm
Lecture2a algorithmLecture2a algorithm
Lecture2a algorithm
 
Banque de France's Workshop on Granularity: François Geerolf's slides, June 2...
Banque de France's Workshop on Granularity: François Geerolf's slides, June 2...Banque de France's Workshop on Granularity: François Geerolf's slides, June 2...
Banque de France's Workshop on Granularity: François Geerolf's slides, June 2...
 
Divide&Conquer & Dynamic Programming
Divide&Conquer & Dynamic ProgrammingDivide&Conquer & Dynamic Programming
Divide&Conquer & Dynamic Programming
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV Syllabus
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
 
Attention is all you need (UPC Reading Group 2018, by Santi Pascual)
Attention is all you need (UPC Reading Group 2018, by Santi Pascual)Attention is all you need (UPC Reading Group 2018, by Santi Pascual)
Attention is all you need (UPC Reading Group 2018, by Santi Pascual)
 
Fair valuation of participating life insurance contracts with jump risk
Fair valuation of participating life insurance contracts with jump riskFair valuation of participating life insurance contracts with jump risk
Fair valuation of participating life insurance contracts with jump risk
 
Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...
Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...
Self-sampling Strategies for Multimemetic Algorithms in Unstable Computationa...
 
Housing Price Models
Housing Price ModelsHousing Price Models
Housing Price Models
 
Matlab 3
Matlab 3Matlab 3
Matlab 3
 
01 - Analysis of Efficiency.pptx
01 - Analysis of Efficiency.pptx01 - Analysis of Efficiency.pptx
01 - Analysis of Efficiency.pptx
 
Software Metrics
Software MetricsSoftware Metrics
Software Metrics
 
Chapter 2 Linear Programming for business (1).pptx
Chapter 2 Linear Programming for business (1).pptxChapter 2 Linear Programming for business (1).pptx
Chapter 2 Linear Programming for business (1).pptx
 
Biosight: Quantitative Methods for Policy Analysis - Introduction to GAMS, Li...
Biosight: Quantitative Methods for Policy Analysis - Introduction to GAMS, Li...Biosight: Quantitative Methods for Policy Analysis - Introduction to GAMS, Li...
Biosight: Quantitative Methods for Policy Analysis - Introduction to GAMS, Li...
 
Measuring credit risk in a large banking system: econometric modeling and emp...
Measuring credit risk in a large banking system: econometric modeling and emp...Measuring credit risk in a large banking system: econometric modeling and emp...
Measuring credit risk in a large banking system: econometric modeling and emp...
 

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

Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 

Recently uploaded (20)

Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 

Sem1 plt xp_02

  • 1. Representing the Logic of Programs with Conditions Objectives In this lesson, you will learn about: Data and data types Using operators Representing decisions in a flowchart ©NIIT PLT/Lesson 2/Slide 1 of 33
  • 2. Representing the Logic of Programs with Conditions Variables and Constants Flowchart to display the sum of two numbers Start Accept the First Number Accept the Second Number Add the two Numbers and Store the Result Display the Result Stop ©NIIT PLT/Lesson 2/Slide 2 of 33
  • 3. Representing the Logic of Programs with Conditions Variables and Constants (Contd.) The internal memory consists of different locations in which data is stored A computer needs to identify the memory locations to be able to retrieve values from or store values in them The value of a variable changes each time the set of instructions is executed The values stored in the variables are known as constants ©NIIT PLT/Lesson 2/Slide 3 of 33
  • 4. Representing the Logic of Programs with Conditions Variables and Constants (Contd.) Constants 10 15 25 nNum1 nNum2 nSum Variables ©NIIT PLT/Lesson 2/Slide 4 of 33
  • 5. Representing the Logic of Programs with Conditions Variables and Constants (Contd.) Flowchart to display the sum of two numbers using variables. Start Accept nNum1 Accept nNum2 nSum = nNum1 + nNum2 Display nSum Stop ©NIIT PLT/Lesson 2/Slide 5 of 33
  • 6. Representing the Logic of Programs with Conditions Just a Minute… Identify the variable and constant data in the following situation: Each day, the courier service delivers some letters. The number of letters is different each day. Regardless of the number of letters delivered by the courier service, they are paid a carrying charge of $5. Variable: Constant: ©NIIT PLT/Lesson 2/Slide 6 of 33
  • 7. Representing the Logic of Programs with Conditions Just a Minute… Identify the variables and constants from the list given below: a) Age b) Address c) 21 d) “10, Kingsway Camp” e) “Henri” f) Name g) “185” ©NIIT PLT/Lesson 2/Slide 7 of 33
  • 8. Representing the Logic of Programs with Conditions Data Types Numeric Numeric variables can contain only numbers These variables can be used in arithmetic operations Character Character variables can contain any combination of letters, numbers, and special characters These variables cannot be used for calculation ©NIIT PLT/Lesson 2/Slide 8 of 33
  • 9. Representing the Logic of Programs with Conditions Data Types Declaring Variables Start numeric nNum1, nNum2, nSum Accept nNum1 Accept nNum2 nSum = nNum1 + nNum2 Display nSum Stop ©NIIT PLT/Lesson 2/Slide 9 of 33
  • 10. Representing the Logic of Programs with Conditions Data Types Variable Naming Conventions ® Thefirst letter of the variable may indicate the data type used ® Thevariable name should clearly describe its purpose ® In case of multiple words, the first letter of each word could be capitalized for better readability ©NIIT PLT/Lesson 2/Slide 10 of 33
  • 11. Representing the Logic of Programs with Conditions Using Operators Operators are tools for some predefined operations The operators that are used in flowcharts are: Arithmetic operators Relational operators Logical operators ©NIIT PLT/Lesson 2/Slide 11 of 33
  • 12. Representing the Logic of Programs with Conditions Using Operators Arithmetic operators Arithmetic operators are used to perform arithmetic calculations The symbols that represent arithmetic operations are called arithmetic operators (*, /, +, -, %) Relational operators Relational operators are used to test the relationship between two variables or the relationship between a variable and a constant There are six relational operators (=,,,!=,=,=) ©NIIT PLT/Lesson 2/Slide 12 of 33
  • 13. Representing the Logic of Programs with Conditions Using Operators Logical operators Logical operators (AND, OR, NOT) are used to combine expressions containing relational operators ® nNum1 = 7 AND nNum2 5 ® nNum1 = 7 OR nNum2 5 ® NOT nNum2 = 5 Precedence of the execution of logical operators are NOT, AND, and OR. ©NIIT PLT/Lesson 2/Slide 13 of 33
  • 14. Representing the Logic of Programs with Conditions Just a Minute… Draw a flowchart to accept item name, price, and quantity. You need to calculate value as the product of price and quantity, and display the calculated value and the item name using variables. ©NIIT PLT/Lesson 2/Slide 14 of 33
  • 15. Representing the Logic of Programs with Conditions Representing Decisions in a Flowchart Many problems require decisions to be made All decisions may or may not state an action to be taken if the condition is false ©NIIT PLT/Lesson 2/Slide 15 of 33
  • 16. Representing the Logic of Programs with Conditions Representing Decisions in a Flowchart Flowchart Segment to Compare Two Numbers and Check for Equality Is nNum1 = No nNum2 ? Yes Display “The Display “The numbers are numbers are equal” not equal” ©NIIT PLT/Lesson 2/Slide 16 of 33
  • 17. Representing the Logic of Programs with Conditions Example Accept two numbers and print the larger of the two numbers. Start numeric nNum1, nNum2 Accept nNum1 Accept nNum2 A ©NIIT PLT/Lesson 2/Slide 17 of 33
  • 18. Representing the Logic of Programs with Conditions Example (Contd.) A Is Yes Display “ The nNum1=nNum2? numbers are equal” No Is Yes nNum1nNum2? Display nNum1 No Display nNum2 Stop ©NIIT PLT/Lesson 2/Slide 18 of 33
  • 19. Representing the Logic of Programs with Conditions Example Print the value of nX only if the value of nX is greater than 10 and nX is an even number. Start numeric nX Accept nX Is No nX10 AND nX%2=0? Yes Display nX Stop ©NIIT PLT/Lesson 2/Slide 19 of 33
  • 20. Representing the Logic of Programs with Conditions Example Accept the year and then determine whether the year is a leap year or not. A leap year is one that is divisible by 4, other than a century year, such as 1900. A century year, which is divisible by 400, such as 2000, is also a leap year. To evaluate the given condition, we can interpret this as: If year is divisible by 4 AND not divisible by 100 OR divisible by 400, it is a leap year. ©NIIT PLT/Lesson 2/Slide 20 of 33
  • 21. Representing the Logic of Programs with Conditions Flowchart to Determine the Leap Year Start numeric nYear Display “ Please enter a year” Accept nYear A ©NIIT PLT/Lesson 2/Slide 21 of 33
  • 22. Representing the Logic of Programs with Conditions Flowchart to Determine the Leap Year (Contd.) A Is nYear % 4=0 AND No Display “ This is (nYear % 100 !=0 OR not a leap year” nYear % 400=0) ? Yes Display “This is a leap year” Stop ©NIIT PLT/Lesson 2/Slide 22 of 33
  • 23. Representing the Logic of Programs with Conditions Example To decide about the discount percentage on a TV, the sales person needs to check the type of TV. If the TV is Black and White [B], the discount will be 5 percent of the selling price. If the type of TV is colored[C], then he has to verify the size of TV screen. For 14 inches screen, discount is 8 percent of the selling price and for 21 inches screen, the discount is 10 percent of the selling price. ©NIIT PLT/Lesson 2/Slide 23 of 33
  • 24. Representing the Logic of Programs with Conditions Flowchart to Calculate Discount Start numeric nScreen, nDiscount character cType Accept cType Accept nScreen Is Yes cType=‘B’? nDiscount=5% of SP No Is Yes Is Yes nDiscount=8% of SP cType=‘C’? nScreen=14? No No Is Yes nDiscount=10% of SP nScreen=21? No Stop ©NIIT PLT/Lesson 2/Slide 24 of 33
  • 25. Representing the Logic of Programs with Conditions Problem Statement 2.P.1 Study the given flowchart and answer the following questions. What will be output when: a) nNum=7 b) nNum=3 c) nNum=11 ©NIIT PLT/Lesson 2/Slide 25 of 33
  • 26. Representing the Logic of Programs with Conditions Problem Statement 2.P.1(Contd.) Start numeric nNum Accept nNum Is Yes nNum10? Display “ GOOD” No Is Yes nNum5? Display “OK” No Display “REJECT” Stop ©NIIT PLT/Lesson 2/Slide 26 of 33
  • 27. Representing the Logic of Programs with Conditions Problem Statement 2.P.2 Study the flowchart and answer the following questions. What will be the output when: a) nX=150 and nY=75 b) nX=90 and nY=50 c) nX=40 and nY=80 ©NIIT PLT/Lesson 2/Slide 27 of 33
  • 28. Representing the Logic of Programs with Conditions Problem Statement 2.P.2 (Contd.) Start numeric nX, nY Accept nX Accept nY Is Yes Is Yes nX nY ? nX 100 ? Display “ GOOD” No No Is No nY 100 ? Yes Display nY Stop ©NIIT PLT/Lesson 2/Slide 28 of 33
  • 29. Representing the Logic of Programs with Conditions Problem Statement 2.P.3 Draw a flowchart to accept a number and then find out whether or not the number is divisible by 5. ©NIIT PLT/Lesson 2/Slide 29 of 33
  • 30. Representing the Logic of Programs with Conditions Problem Statement 2.P.4 Draw a flowchart to accept three numbers and display the largest number. ©NIIT PLT/Lesson 2/Slide 30 of 33
  • 31. Representing the Logic of Programs with Conditions Problem Statement 2.P.5 Candidates have to enter their age. The age cannot be negative. If a negative age is entered, an error message has to be displayed, otherwise the age is displayed. Represent the error checking logic for this situation using a flowchart. ©NIIT PLT/Lesson 2/Slide 31 of 33
  • 32. Representing the Logic of Programs with Conditions Summary In this lesson, you learned that: Data can be categorized as a constant or variable Data types can be: Numeric Character The operators are: Arithmetic Relational Logical ©NIIT PLT/Lesson 2/Slide 32 of 33
  • 33. Representing the Logic of Programs with Conditions Summary (Contd.) Arithmetic operators are used to perform arithmetic calculations. The symbols that represents arithmetic operations are called arithmetic operators (*,/,+,-,%). Relational operators are used to test the relationship between two variables. The symbols that represent relational operations are called relational operators (,,=,!=). Logical operators (AND, OR, NOT) are used to combine expressions containing relational operators. The decision box is used to apply conditions by asking a question in a flowchart. ©NIIT PLT/Lesson 2/Slide 33 of 33