SlideShare una empresa de Scribd logo
1 de 44
Descargar para leer sin conexión
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                          Computer Fundamentals: Pradeep K. Sinha & Priti Sinha




Ref Page   Chapter 11: Planning the Computer Program             Slide 1/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Learning Objectives

      In this chapter you will learn about:


          § Programs must be planned before they are written
          § Algorithm
          § Flowchart
          § Pseudocode
          § Plan the logic of a computer program
          § Commonly used tools for program planning and
            their use




Ref Page 183     Chapter 11: Planning the Computer Program             Slide 2/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Purpose of Program Planning

      § To write a correct program, a programmer must write
        each and every instruction in the correct sequence
      § Logic (instruction sequence) of a program can be very
        complex
      § Hence, programs must be planned before they are
        written to ensure program instructions are:
           § Appropriate for the problem
           § In the correct sequence




Ref Page 183      Chapter 11: Planning the Computer Program             Slide 3/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

  Algorithm

      §   Refers to the logic of a program and a step-by-step
          description of how to arrive at the solution of a given
          problem
      §   In order to qualify as an algorithm, a sequence of
          instructions must have following characteristics:
          § Each and every instruction should be precise and
            unambiguous
          § Each instruction should be such that it can be performed in
            a finite time
          § One or more instructions should not be repeated infinitely.
            This ensures that the algorithm will ultimately terminate
          § After performing the instructions, that is after the algorithm
            terminates, the desired results must be obtained




Ref Page 184      Chapter 11: Planning the Computer Program             Slide 4/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

  Sample Algorithm (Example 1)

      There are 50 students in a class who appeared in their
      final examination. Their mark sheets have been given to
      you.

      The division column of the mark sheet contains the
      division (FIRST, SECOND, THIRD or FAIL) obtained by the
      student.

      Write an algorithm to calculate and print the total number
      of students who passed in FIRST division.




Ref Page 184     Chapter 11: Planning the Computer Program             Slide 5/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                   Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

  Sample Algorithm (Example 1)
                                                                               (contd…)
      Step 1: Initialize Total_First_Division and
              Total_Marksheets_Checked to zero.

      Step 2: Take the mark sheet of the next student.

      Step 3: Check the division column of the mark sheet to see if it is
              FIRST, if no, go to Step 5.

      Step 4: Add 1 to Total_First_Division.

      Step 5: Add 1 to Total_Marksheets_Checked.

      Step 6: Is Total_Marksheets_Checked = 50, if no, go to Step 2.

      Step 7: Print Total_First_Division.

      Step 8: Stop.




Ref Page 184        Chapter 11: Planning the Computer Program             Slide 6/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

  Sample Algorithm (Example 2)

      There are 100 employees in an organization. The organization
      wants to distribute annual bonus to the employees based on their
      performance. The performance of the employees is recorded in
      their annual appraisal forms.
      Every employee’s appraisal form contains his/her basic salary and
      the grade for his/her performance during the year. The grade is of
      three categories – ‘A’ for outstanding performance, ‘B’ for good
      performance, and ‘C’ for average performance.
      It has been decided that the bonus of an employee will be 100% of
      the basic salary for outstanding performance, 70% of the basic
      salary for good performance, 40% of the basic salary for average
      performance, and zero for all other cases.
      Write an algorithm to calculate and print the total bonus amount to
      be distributed by the organization.




Ref Page 185      Chapter 11: Planning the Computer Program             Slide 7/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                         Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

  Sample Algorithm (Example 2)

      Step 1:   Initialize Total_Bonus and Total_Employees_Checked to zero.          (contd…)

      Step 2:   Initialize Bonus and Basic_Salary to zero.

      Step 3:   Take the appraisal form of the next employee.

      Step 4:   Read the employee’s Basic_Salary and Grade.

      Step 5:   If Grade = A, then Bonus = Basic_Salary. Go to Step 8.

      Step 6:   If Grade = B, then Bonus = Basic_Salary x 0.7. Go to Step 8.

      Step 7:   If Grade = C, then Bonus = Basic_Salary x 0.4.

      Step 8:   Add Bonus to Total_Bonus.

      Step 9:   Add 1 to Total_Employees_Checked.

      Step 10: If Total_Employees_Checked < 100, then go to Step 2.

      Step 11: Print Total_Bonus.

      Step 12: Stop.




Ref Page 185           Chapter 11: Planning the Computer Program                Slide 8/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                               Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Representation of Algorithms

      § As programs
      § As flowcharts
      § As pseudocodes

      When an algorithm is represented in the form of a
      programming language, it becomes a program

      Thus, any program is an algorithm, although the
      reverse is not true




Ref Page 185    Chapter 11: Planning the Computer Program             Slide 9/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

  Flowchart

      § Flowchart is a pictorial representation of an algorithm
      § Uses symbols (boxes of different shapes) that have
        standardized meanings to denote different types of
        instructions
      § Actual instructions are written within the boxes
      § Boxes are connected by solid lines having arrow marks to
        indicate the exact sequence in which the instructions are
        to be executed
      § Process of drawing a flowchart for an algorithm is called
        flowcharting




Ref Page 186     Chapter 11: Planning the Computer Program             Slide 10/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Basic Flowchart Symbols



         Terminal           Input/Output                 Processing




          Decision            Flow lines                 Connectors




Ref Page 187     Chapter 11: Planning the Computer Program             Slide 11/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                     Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

  Examples of Decision Symbol




                              No               A<B          Compare        A>B
           Is I = 10?
                                                             A&B


                Yes                                               A=B


   (a) A two-way branch decision.                (b) A three-way branch decision.




Ref Page 188          Chapter 11: Planning the Computer Program             Slide 12/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                               Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

  Examples of Decision Symbol
                                                                           (contd…)




                                I=?



               =0   =1      =2      =3     =4      =5       = Other


               (c) A multiple-way branch decision.




Ref Page 188    Chapter 11: Planning the Computer Program             Slide 13/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                               Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Sample Flowchart (Example 3)

      A student appears in an examination, which consists of
      total 10 subjects, each subject having maximum marks
      of 100.
      The roll number of the student, his/her name, and the
      marks obtained by him/her in various subjects are
      supplied as input data.
      Such a collection of related data items, which is treated
      as a unit is known as a record.
      Draw a flowchart for the algorithm to calculate the
      percentage marks obtained by the student in this
      examination and then to print it along with his/her roll
      number and name.




Ref Page 188    Chapter 11: Planning the Computer Program             Slide 14/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                              Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Sample Flowchart (Example 3)
                                Start                                     (contd…)



                          Read input data



                         Add marks of all
                       subjects giving Total



                     Percentage = Total / 10



                        Write output data


                                Stop



Ref Page 189   Chapter 11: Planning the Computer Program             Slide 15/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                               Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Sample Flowchart (Example 4)

      50 students of a class appear in the examination of
      Example 3.
      Draw a flowchart for the algorithm to calculate and print
      the percentage marks obtained by each student along
      with his/her roll number and name.




Ref Page 189    Chapter 11: Planning the Computer Program             Slide 16/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Sample Flowchart (Example 4)

                       Start                                                 (contd…)



                  Read input data


                                             Flowchart for the solution
                  Add marks of all
                                             of Example 4 with an
                subjects giving Total
                                             infinite (endless) process
                                             loop.

               Percentage = Total / 10



                 Write output data




Ref Page 190      Chapter 11: Planning the Computer Program             Slide 17/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                    Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Sample Flowchart (Example 4)
                         Start                                                   (contd…)

                       Count = 0

                    Read input data

               Add marks of all subjects giving Total


                 Percentage = Total/10


                    Write output data
                                                    Flowchart for the solution
                     Add 1 to Count
                                                    of Example 4.
       No
                     Is Count = 50?

                             Yes
                          Stop



Ref Page 191         Chapter 11: Planning the Computer Program             Slide 18/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                   Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Sample Flowchart (Example 4)
                      Start                                                    (contd…)


                 Read input data



                                           Yes
               Is Rollno = 0000000?
                                                         Generalized flowchart
                         No                              for the solution of
           Add marks of all subjects                     Example 4 using the
                                              Stop
                giving Total                             concept of trailer
                                                         record. Here the
                                                         process loop is
           Percentage = Total / 10                       terminated by detecting
                                                         a special non-data
                                                         record.
               Write output data




Ref Page 191        Chapter 11: Planning the Computer Program             Slide 19/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Sample Flowchart (Example 5)

      For the examination of Example 3, we want to make a
      list of only those students who have passed (obtained
      30% or more marks) in the examination.
      In the end, we also want to print out the total number of
      students who have passed.
      Assuming that the input data of all the students is
      terminated by a trailer record, which has sentinel value
      of 9999999 for Rollno, draw a flowchart for the
      algorithm to do this.




Ref Page 192     Chapter 11: Planning the Computer Program             Slide 20/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                        Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Sample Flowchart (Example 5)
                               Start                                                (contd…)
                             Count = 0

                          Read input data

                                                         Yes
                      Is Rollno = 9999999?
                                   No                          Write Count
               Add marks of all subjects giving Total             Stop

                      Percentage = Total/10

                      Is Percentage = > 30?
                                                         No

                                  Yes
                        Write output data

                         Add 1 to Count




Ref Page 193          Chapter 11: Planning the Computer Program                Slide 21/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Sample Flowchart (Example 6)

      Suppose the input data of each student for the examination of
      Example 3 also contains information regarding the sex of the
      candidate in the field named Sexcode having values M (for
      male) or F (for female).
      We want to make a list of only those female students who have
      passed in second division (obtained 45% or more but less than
      60% marks).
      In the end, we also want to print out the total number of such
      students.
      Assuming that the input data of all the students is terminated
      by a trailer record, which has a sentinel value of Z for Sexcode,
      draw a flowchart for the algorithm to do this.




Ref Page 193      Chapter 11: Planning the Computer Program             Slide 22/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                   Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Sample Flowchart (Example 6)
                                      Start

                                    Count = 0

               1                 Read input data



                                                              Yes   2
                               Is Sexcode = Z?

                                           No

               1   No          Is Sexcode = F?

                                         Yes
                     Add marks of all subjects giving Total


                           Percentage = Total / 10

                                       3




Ref Page 195       Chapter 11: Planning the Computer Program              Slide 23/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                   Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Sample Flowchart (Example 4)
                                                                                 (contd…)
                                       3


               No
        1                    Is Percentage = > 45?


                                           Yes
                                                                       2
               No
        1                      Is Percentage < 60?

                                                                  Write Count
                                           Yes
                               Write output data
                                                                      Stop

                                 Add 1 to Count


                                       1




Ref Page 195        Chapter 11: Planning the Computer Program                Slide 24/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                               Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Levels of Flowchart

      § Flowchart that outlines the main segments of a program
        or that shows less details is a macro flowchart

      § Flowchart with more details is a micro flowchart, or
        detailed flowchart

      § There are no set standards on the amount of details that
        should be provided in a flowchart




Ref Page 196    Chapter 11: Planning the Computer Program             Slide 25/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                  Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Example of Micro Flowchart


         Part of a macro                                1
            flowchart
                                                      I=1              A micro
                                                                      Flowchart
                                                    Total = 0

                                         Total = Total + Marks (I)
        Add marks of all
      subjects giving Total
                                                     I=I+1

                                       No
                                                    Is I > 10?
                                                            Yes
                                                        1




Ref Page 196       Chapter 11: Planning the Computer Program             Slide 26/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Flowcharting Rules

      § First chart the main line of logic, then incorporate detail

      § Maintain a consistent level of detail for a given flowchart

      § Do not chart every detail of the program. A reader who is
        interested in greater details can refer to the program itself

      § Words in the flowchart symbols should be common
        statements and easy to understand




Ref Page 196     Chapter 11: Planning the Computer Program             Slide 27/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                               Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Flowcharting Rules
                                                                           (contd…)
      § Be consistent in using names and variables in the
        flowchart

      § Go from left to right and top to bottom in
        constructing flowcharts

      § Keep the flowchart as simple as possible. Crossing of
        flow lines should be avoided as far as practicable

      § If a new flowcharting page is needed, it is
        recommended that the flowchart be broken at an
        input or output point.

      § Properly labeled connectors should be used to link
        the portions of the flowchart on different pages


Ref Page 197    Chapter 11: Planning the Computer Program             Slide 28/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

  Advantages of Flowchart

      § Better Communication
      § Proper program documentation
      § Efficient coding
      § Systematic debugging
      § Systematic testing




Ref Page 197     Chapter 11: Planning the Computer Program             Slide 29/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                               Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Limitations of Flowchart

      § Flowcharts are very time consuming and laborious to
        draw (especially for large complex programs)
      § Redrawing a flowchart for incorporating changes/
        modifications is a tedious task
      § There are no standards determining the amount of detail
        that should be included in a flowchart




Ref Page 198    Chapter 11: Planning the Computer Program             Slide 30/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                               Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Pseudocode

      § A program planning tool where program logic is written in
        an ordinary natural language using a structure that
        resembles computer instructions

      § “ Pseudo” means imitation or false and “ Code” refers to
        the instructions written in a programming language.
        Hence, pseudocode is an imitation of actual computer
        instructions

      § Because it emphasizes the design of the program,
        pseudocode is also called Program Design Language
        (PDL)




Ref Page 198    Chapter 11: Planning the Computer Program             Slide 31/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Basic Logic (Control) Structures

      Any program logic can be expressed by using only
      following three simple logic structures:

           1. Sequence logic,
           2. Selection logic, and
           3. Iteration (or looping) logic

      Programs structured by using only these three logic
      structures are called structured programs, and the
      technique of writing such programs is known as
      structured programming




Ref Page 199      Chapter 11: Planning the Computer Program             Slide 32/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Sequence Logic

      It is used for performing instructions one after another
      in sequence.




                  Process 1


                                                   Process 1
                  Process 2
                                                   Process 2




               (a) Flowchart                     (b) Pseudocode



Ref Page 199     Chapter 11: Planning the Computer Program             Slide 33/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                  Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Selection Logic

      •   Also known as decision logic, it is used for making
          decisions

      •   Three   popularly used selection logic structures are
             1.    IF…THEN…ELSE
             2.    IF…THEN
             3.    CASE




Ref Page 200       Chapter 11: Planning the Computer Program             Slide 34/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                  Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Selection Logic (IF…THEN…ELSE Structure)



      Yes                         No                 IF Condition
                IF (condition)
                                                         THEN       Process 1
         THEN                ELSE                        ELSE       Process 2

  Process 1                      Process 2
                                                     ENDIF




               (a) Flowchart                         (b) Pseudocode




Ref Page 200       Chapter 11: Planning the Computer Program             Slide 35/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Selection Logic (IF…THEN Structure)


        Yes                      No
                IF (condition)
                                                  IF Condition

           THEN
                                                      THEN       Process 1
    Process 1
                                                  ENDIF




                (a) Flowchart                   (b) Pseudocode




Ref Page 200      Chapter 11: Planning the Computer Program             Slide 36/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                     Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Selection Logic (CASE Structure)

                     Yes
       Type 1                  Process 1

               No
                     Yes
       Type 2                  Process 2              CASE Type

                                                          Case Type 1:     Process 1
               No
                                                          Case Type 2:     Process 2

                     Yes
       Type n                  Process n
                                                          Case Type n:     Process n
               No
                                                      ENDCASE

               (a) Flowchart
                                                          (b) Pseudocode



Ref Page 201         Chapter 11: Planning the Computer Program              Slide 37/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Iteration (or Looping) Logic

      §   Used to produce loops in program logic when one or
          more instructions may be executed several times
          depending on some conditions

      §   Two popularly used iteration logic structures are

               1. DO…WHILE
               2. REPEAT…UNTIL




Ref Page 201     Chapter 11: Planning the Computer Program             Slide 38/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                  Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
 Iteration (or Looping) Logic
 (DO…WHILE Structure)



                                    False
                 Condition?

                         True
                 Process 1                              DO WHILE Condition
                                                             Process 1
                          Block
                                                             Process n
                 Process n                             ENDDO



               (a) Flowchart                      (b) Pseudocode




Ref Page 202     Chapter 11: Planning the Computer Program               Slide 39/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

  Iteration (or Looping) Logic
  (REPEAT…UNTIL Structure)



                  Process 1



                                             REPEAT
                                                   Process 1
                  Process n


                                                   Process n
       False
                 Condition?                  UNTIL Condition

                        True
               (a) Flowchart               (b) Pseudocode




Ref Page 202     Chapter 11: Planning the Computer Program             Slide 40/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

  Sample Pseudocode (for Example 6)

               Set Count to zero
               Read first student record
               DO WHILE Sexcode is not equal to Z
                   IF Sexcode = F THEN
                        Calculate Percentage
                        IF Percentage = > 45 THEN
                            IF Percentage < 60 THEN
                                Write output data
                               Add 1 to Count
                            ENDIF
                        ENDIF
                   ENDIF
                   Read next student record
               ENDDO
               Write Count
               Stop




Ref Page 203     Chapter 11: Planning the Computer Program             Slide 41/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

  Advantages of Pseudocode

      § Converting a pseudocode to a programming language
        is much more easier than converting a flowchart to a
        programming language

      § As compared to a flowchart, it is easier to modify the
        pseudocode of a program logic when program
        modifications are necessary

      § Writing of pseudocode involves much less time and
        effort than drawing an equivalent flowchart as it has
        only a few rules to follow




Ref Page 204     Chapter 11: Planning the Computer Program             Slide 42/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Limitations of Pseudocode

      § In case of pseudocode, a graphic representation of
        program logic is not available

      § There are no standard rules to follow in using
        pseudocode

      § Different programmers use their own style of writing
        pseudocode and hence communication problem
        occurs due to lack of standardization

      § For a beginner, it is more difficult to follow the logic
        of or write pseudocode, as compared to flowcharting




Ref Page 204     Chapter 11: Planning the Computer Program             Slide 43/44
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
                                 Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

 Key Words/Phrases

      §   Algorithm
      §   Basic logic structures
      §   Control structures
      §   Flowchart
      §   Iteration logic
      §   Looping logic
      §   Micro flowchart
      §   Macro flowchart
      §   Pseudocode
      §   Program Design Language (PDL)
      §   Sequence logic
      §   Selection logic
      §   Sentinel value
      §   Structured programming
      §   Trailer record




Ref Page 204      Chapter 11: Planning the Computer Program             Slide 44/44

Más contenido relacionado

La actualidad más candente

Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & LanguagesGaditek
 
Introduction to Algorithms & flow charts
Introduction to Algorithms & flow chartsIntroduction to Algorithms & flow charts
Introduction to Algorithms & flow chartsYash Gupta
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and FlowchartsDeva Singh
 
Computer Fundamentals Chapter 01 introduction
Computer Fundamentals Chapter 01 introductionComputer Fundamentals Chapter 01 introduction
Computer Fundamentals Chapter 01 introductionSaumya Sahu
 
Computer architecture
Computer architectureComputer architecture
Computer architectureZuhaib Zaroon
 
Basic of Computer fundamental
Basic of Computer fundamental Basic of Computer fundamental
Basic of Computer fundamental Sohan Grover
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compilerIffat Anjum
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and AlgorithmDhaval Kaneria
 
CBSE Grade XI - Computer system overview - Lesson 1
CBSE Grade XI - Computer system overview  - Lesson 1 CBSE Grade XI - Computer system overview  - Lesson 1
CBSE Grade XI - Computer system overview - Lesson 1 sumedhadeshpande5
 
How to execute a C program
How to execute a C  program How to execute a C  program
How to execute a C program Leela Koneru
 
Chapter 04 computer codes
Chapter 04 computer codesChapter 04 computer codes
Chapter 04 computer codesHareem Aslam
 
Chapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to ProgrammingChapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to Programmingmshellman
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming ConceptsJussi Pohjolainen
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJulie Iskander
 
Memory Reference Instructions
Memory Reference InstructionsMemory Reference Instructions
Memory Reference InstructionsRabin BK
 
Process management os concept
Process management os conceptProcess management os concept
Process management os conceptpriyadeosarkar91
 

La actualidad más candente (20)

Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
Introduction to Algorithms & flow charts
Introduction to Algorithms & flow chartsIntroduction to Algorithms & flow charts
Introduction to Algorithms & flow charts
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 
Computer Fundamentals Chapter 01 introduction
Computer Fundamentals Chapter 01 introductionComputer Fundamentals Chapter 01 introduction
Computer Fundamentals Chapter 01 introduction
 
Computer architecture
Computer architectureComputer architecture
Computer architecture
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
Basic of Computer fundamental
Basic of Computer fundamental Basic of Computer fundamental
Basic of Computer fundamental
 
Input output module
Input output moduleInput output module
Input output module
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and Algorithm
 
CBSE Grade XI - Computer system overview - Lesson 1
CBSE Grade XI - Computer system overview  - Lesson 1 CBSE Grade XI - Computer system overview  - Lesson 1
CBSE Grade XI - Computer system overview - Lesson 1
 
How to execute a C program
How to execute a C  program How to execute a C  program
How to execute a C program
 
C Programming Unit-4
C Programming Unit-4C Programming Unit-4
C Programming Unit-4
 
Chapter 04 computer codes
Chapter 04 computer codesChapter 04 computer codes
Chapter 04 computer codes
 
Chapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to ProgrammingChapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to Programming
 
C Programming Assignment
C Programming AssignmentC Programming Assignment
C Programming Assignment
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming Concepts
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Memory Reference Instructions
Memory Reference InstructionsMemory Reference Instructions
Memory Reference Instructions
 
Process management os concept
Process management os conceptProcess management os concept
Process management os concept
 

Destacado

Computer Fundamentals Chapter 07 pam
Computer Fundamentals Chapter  07 pamComputer Fundamentals Chapter  07 pam
Computer Fundamentals Chapter 07 pamSaumya Sahu
 
Computer Fundamentals_Chapter 02 bco
Computer Fundamentals_Chapter 02 bcoComputer Fundamentals_Chapter 02 bco
Computer Fundamentals_Chapter 02 bcoSaumya Sahu
 
Computer Fundamentals
Computer FundamentalsComputer Fundamentals
Computer FundamentalsSaumya Sahu
 
Chapter19 multimedia-091006115642-phpapp02 (1)
Chapter19 multimedia-091006115642-phpapp02 (1)Chapter19 multimedia-091006115642-phpapp02 (1)
Chapter19 multimedia-091006115642-phpapp02 (1)Jay Patel
 
Chapter 21 c language
Chapter 21 c languageChapter 21 c language
Chapter 21 c languageHareem Aslam
 
Chapter 05 computer arithmetic
Chapter 05 computer arithmeticChapter 05 computer arithmetic
Chapter 05 computer arithmeticHareem Aslam
 
Chapter 03 number system
Chapter 03 number systemChapter 03 number system
Chapter 03 number systemHareem Aslam
 
Computer Fundamentals Chapter 14 os
Computer Fundamentals Chapter 14 osComputer Fundamentals Chapter 14 os
Computer Fundamentals Chapter 14 osSaumya Sahu
 
Chapter 06 boolean algebra
Chapter 06 boolean algebraChapter 06 boolean algebra
Chapter 06 boolean algebraHareem Aslam
 
Computer Fundamentals Chapter 09 io devices
Computer Fundamentals Chapter 09 io devicesComputer Fundamentals Chapter 09 io devices
Computer Fundamentals Chapter 09 io devicesSaumya Sahu
 
Chapter 02 bco
Chapter 02 bcoChapter 02 bco
Chapter 02 bcoIIUI
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++Pranav Ghildiyal
 
Chapter01 introduction to computer
Chapter01   introduction to computerChapter01   introduction to computer
Chapter01 introduction to computerAinuddin Yousufzai
 
Chapter04 ip addressing networking
Chapter04 ip addressing networkingChapter04 ip addressing networking
Chapter04 ip addressing networkingAinuddin Yousufzai
 

Destacado (20)

Computer Fundamentals Chapter 07 pam
Computer Fundamentals Chapter  07 pamComputer Fundamentals Chapter  07 pam
Computer Fundamentals Chapter 07 pam
 
Computer Fundamentals_Chapter 02 bco
Computer Fundamentals_Chapter 02 bcoComputer Fundamentals_Chapter 02 bco
Computer Fundamentals_Chapter 02 bco
 
Computer Fundamentals
Computer FundamentalsComputer Fundamentals
Computer Fundamentals
 
Chapter19 multimedia-091006115642-phpapp02 (1)
Chapter19 multimedia-091006115642-phpapp02 (1)Chapter19 multimedia-091006115642-phpapp02 (1)
Chapter19 multimedia-091006115642-phpapp02 (1)
 
Chapter 10 cs
Chapter 10 csChapter 10 cs
Chapter 10 cs
 
Chapter 17 dccn
Chapter 17 dccnChapter 17 dccn
Chapter 17 dccn
 
Chapter 21 c language
Chapter 21 c languageChapter 21 c language
Chapter 21 c language
 
Chapter 15 asp
Chapter 15 aspChapter 15 asp
Chapter 15 asp
 
Chapter 05 computer arithmetic
Chapter 05 computer arithmeticChapter 05 computer arithmetic
Chapter 05 computer arithmetic
 
Chapter 03 number system
Chapter 03 number systemChapter 03 number system
Chapter 03 number system
 
Computer Fundamentals Chapter 14 os
Computer Fundamentals Chapter 14 osComputer Fundamentals Chapter 14 os
Computer Fundamentals Chapter 14 os
 
Chapter 06 boolean algebra
Chapter 06 boolean algebraChapter 06 boolean algebra
Chapter 06 boolean algebra
 
Computer Fundamentals Chapter 09 io devices
Computer Fundamentals Chapter 09 io devicesComputer Fundamentals Chapter 09 io devices
Computer Fundamentals Chapter 09 io devices
 
Chapter 02 bco
Chapter 02 bcoChapter 02 bco
Chapter 02 bco
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++
 
Chapter03 number system
Chapter03   number systemChapter03   number system
Chapter03 number system
 
Chapter01 introduction to computer
Chapter01   introduction to computerChapter01   introduction to computer
Chapter01 introduction to computer
 
Unicode
UnicodeUnicode
Unicode
 
Chapter05 secondary storage
Chapter05   secondary storageChapter05   secondary storage
Chapter05 secondary storage
 
Chapter04 ip addressing networking
Chapter04 ip addressing networkingChapter04 ip addressing networking
Chapter04 ip addressing networking
 

Similar a Computer Fundamentals Chapter 11 pcp

Chapter 01 Planning Computer Program (re-upload)
Chapter 01 Planning Computer Program (re-upload)Chapter 01 Planning Computer Program (re-upload)
Chapter 01 Planning Computer Program (re-upload)bluejayjunior
 
Chapter 11-PCP.pdf
Chapter 11-PCP.pdfChapter 11-PCP.pdf
Chapter 11-PCP.pdfranapoonam1
 
Chapter 10 cs 2o-p
Chapter 10 cs 2o-pChapter 10 cs 2o-p
Chapter 10 cs 2o-pIIUI
 
Computer fundamental basic comuter organization [www.studysharebd.com]
Computer fundamental basic comuter organization [www.studysharebd.com]Computer fundamental basic comuter organization [www.studysharebd.com]
Computer fundamental basic comuter organization [www.studysharebd.com]Rafiq Azad
 
Software
SoftwareSoftware
SoftwareIIUI
 
Software Introduction
Software IntroductionSoftware Introduction
Software IntroductionIIUI
 
Chapter 02 Computer Languages (re-upload)
Chapter 02 Computer Languages (re-upload)Chapter 02 Computer Languages (re-upload)
Chapter 02 Computer Languages (re-upload)bluejayjunior
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfMMRF2
 
Chapter14 os-121120003310-phpapp02
Chapter14 os-121120003310-phpapp02Chapter14 os-121120003310-phpapp02
Chapter14 os-121120003310-phpapp02Tapas Das
 
Chapter14 os-121120003310-phpapp02
Chapter14 os-121120003310-phpapp02Chapter14 os-121120003310-phpapp02
Chapter14 os-121120003310-phpapp02Tapas Das
 
Into to programming fundamentals
Into to programming fundamentalsInto to programming fundamentals
Into to programming fundamentalsAns Ali
 
Chapter 02 bco 3o-p
Chapter 02 bco 3o-pChapter 02 bco 3o-p
Chapter 02 bco 3o-pIIUI
 
Chapter02 basic computer organization
Chapter02   basic computer organizationChapter02   basic computer organization
Chapter02 basic computer organizationAinuddin Yousufzai
 
Chapter 02 bco
Chapter 02 bcoChapter 02 bco
Chapter 02 bcokhalid zia
 
Chapter 02 bco 2o-p
Chapter 02 bco 2o-pChapter 02 bco 2o-p
Chapter 02 bco 2o-pIIUI
 

Similar a Computer Fundamentals Chapter 11 pcp (20)

Chapter 01 Planning Computer Program (re-upload)
Chapter 01 Planning Computer Program (re-upload)Chapter 01 Planning Computer Program (re-upload)
Chapter 01 Planning Computer Program (re-upload)
 
Chapter 11 pcp
Chapter 11 pcpChapter 11 pcp
Chapter 11 pcp
 
Chapter 11-PCP.pdf
Chapter 11-PCP.pdfChapter 11-PCP.pdf
Chapter 11-PCP.pdf
 
Chapter 13 sio
Chapter 13 sioChapter 13 sio
Chapter 13 sio
 
Chapter 10 cs 2o-p
Chapter 10 cs 2o-pChapter 10 cs 2o-p
Chapter 10 cs 2o-p
 
Chapter 10 cs
Chapter 10 csChapter 10 cs
Chapter 10 cs
 
Chapter06 computer software
Chapter06   computer softwareChapter06   computer software
Chapter06 computer software
 
Computer fundamental basic comuter organization [www.studysharebd.com]
Computer fundamental basic comuter organization [www.studysharebd.com]Computer fundamental basic comuter organization [www.studysharebd.com]
Computer fundamental basic comuter organization [www.studysharebd.com]
 
Software
SoftwareSoftware
Software
 
Software Introduction
Software IntroductionSoftware Introduction
Software Introduction
 
Chapter 02 Computer Languages (re-upload)
Chapter 02 Computer Languages (re-upload)Chapter 02 Computer Languages (re-upload)
Chapter 02 Computer Languages (re-upload)
 
Chapter 12 cl
Chapter 12 clChapter 12 cl
Chapter 12 cl
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
 
Chapter14 os-121120003310-phpapp02
Chapter14 os-121120003310-phpapp02Chapter14 os-121120003310-phpapp02
Chapter14 os-121120003310-phpapp02
 
Chapter14 os-121120003310-phpapp02
Chapter14 os-121120003310-phpapp02Chapter14 os-121120003310-phpapp02
Chapter14 os-121120003310-phpapp02
 
Into to programming fundamentals
Into to programming fundamentalsInto to programming fundamentals
Into to programming fundamentals
 
Chapter 02 bco 3o-p
Chapter 02 bco 3o-pChapter 02 bco 3o-p
Chapter 02 bco 3o-p
 
Chapter02 basic computer organization
Chapter02   basic computer organizationChapter02   basic computer organization
Chapter02 basic computer organization
 
Chapter 02 bco
Chapter 02 bcoChapter 02 bco
Chapter 02 bco
 
Chapter 02 bco 2o-p
Chapter 02 bco 2o-pChapter 02 bco 2o-p
Chapter 02 bco 2o-p
 

Más de Saumya Sahu

Paper presentation-nano-robots
Paper presentation-nano-robotsPaper presentation-nano-robots
Paper presentation-nano-robotsSaumya Sahu
 
Paper presentation-nano-robots
Paper presentation-nano-robotsPaper presentation-nano-robots
Paper presentation-nano-robotsSaumya Sahu
 
Engineering Symbols
Engineering SymbolsEngineering Symbols
Engineering SymbolsSaumya Sahu
 
Gate-2013(Computer Science) Que_Ans
Gate-2013(Computer Science) Que_AnsGate-2013(Computer Science) Que_Ans
Gate-2013(Computer Science) Que_AnsSaumya Sahu
 
Project management
Project managementProject management
Project managementSaumya Sahu
 
Computer Fundamentals Chapter 16 bdp
Computer Fundamentals Chapter 16 bdpComputer Fundamentals Chapter 16 bdp
Computer Fundamentals Chapter 16 bdpSaumya Sahu
 
Computer Fundamentals Chapter 08 secondary storage
Computer Fundamentals Chapter 08 secondary storageComputer Fundamentals Chapter 08 secondary storage
Computer Fundamentals Chapter 08 secondary storageSaumya Sahu
 
Computer networks
Computer networksComputer networks
Computer networksSaumya Sahu
 
Computer networks (2)
Computer networks (2)Computer networks (2)
Computer networks (2)Saumya Sahu
 
Software project management
Software project managementSoftware project management
Software project managementSaumya Sahu
 

Más de Saumya Sahu (11)

Cloud computing
Cloud computingCloud computing
Cloud computing
 
Paper presentation-nano-robots
Paper presentation-nano-robotsPaper presentation-nano-robots
Paper presentation-nano-robots
 
Paper presentation-nano-robots
Paper presentation-nano-robotsPaper presentation-nano-robots
Paper presentation-nano-robots
 
Engineering Symbols
Engineering SymbolsEngineering Symbols
Engineering Symbols
 
Gate-2013(Computer Science) Que_Ans
Gate-2013(Computer Science) Que_AnsGate-2013(Computer Science) Que_Ans
Gate-2013(Computer Science) Que_Ans
 
Project management
Project managementProject management
Project management
 
Computer Fundamentals Chapter 16 bdp
Computer Fundamentals Chapter 16 bdpComputer Fundamentals Chapter 16 bdp
Computer Fundamentals Chapter 16 bdp
 
Computer Fundamentals Chapter 08 secondary storage
Computer Fundamentals Chapter 08 secondary storageComputer Fundamentals Chapter 08 secondary storage
Computer Fundamentals Chapter 08 secondary storage
 
Computer networks
Computer networksComputer networks
Computer networks
 
Computer networks (2)
Computer networks (2)Computer networks (2)
Computer networks (2)
 
Software project management
Software project managementSoftware project management
Software project management
 

Computer Fundamentals Chapter 11 pcp

  • 1. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Ref Page Chapter 11: Planning the Computer Program Slide 1/44
  • 2. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Learning Objectives In this chapter you will learn about: § Programs must be planned before they are written § Algorithm § Flowchart § Pseudocode § Plan the logic of a computer program § Commonly used tools for program planning and their use Ref Page 183 Chapter 11: Planning the Computer Program Slide 2/44
  • 3. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Purpose of Program Planning § To write a correct program, a programmer must write each and every instruction in the correct sequence § Logic (instruction sequence) of a program can be very complex § Hence, programs must be planned before they are written to ensure program instructions are: § Appropriate for the problem § In the correct sequence Ref Page 183 Chapter 11: Planning the Computer Program Slide 3/44
  • 4. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Algorithm § Refers to the logic of a program and a step-by-step description of how to arrive at the solution of a given problem § In order to qualify as an algorithm, a sequence of instructions must have following characteristics: § Each and every instruction should be precise and unambiguous § Each instruction should be such that it can be performed in a finite time § One or more instructions should not be repeated infinitely. This ensures that the algorithm will ultimately terminate § After performing the instructions, that is after the algorithm terminates, the desired results must be obtained Ref Page 184 Chapter 11: Planning the Computer Program Slide 4/44
  • 5. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Algorithm (Example 1) There are 50 students in a class who appeared in their final examination. Their mark sheets have been given to you. The division column of the mark sheet contains the division (FIRST, SECOND, THIRD or FAIL) obtained by the student. Write an algorithm to calculate and print the total number of students who passed in FIRST division. Ref Page 184 Chapter 11: Planning the Computer Program Slide 5/44
  • 6. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Algorithm (Example 1) (contd…) Step 1: Initialize Total_First_Division and Total_Marksheets_Checked to zero. Step 2: Take the mark sheet of the next student. Step 3: Check the division column of the mark sheet to see if it is FIRST, if no, go to Step 5. Step 4: Add 1 to Total_First_Division. Step 5: Add 1 to Total_Marksheets_Checked. Step 6: Is Total_Marksheets_Checked = 50, if no, go to Step 2. Step 7: Print Total_First_Division. Step 8: Stop. Ref Page 184 Chapter 11: Planning the Computer Program Slide 6/44
  • 7. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Algorithm (Example 2) There are 100 employees in an organization. The organization wants to distribute annual bonus to the employees based on their performance. The performance of the employees is recorded in their annual appraisal forms. Every employee’s appraisal form contains his/her basic salary and the grade for his/her performance during the year. The grade is of three categories – ‘A’ for outstanding performance, ‘B’ for good performance, and ‘C’ for average performance. It has been decided that the bonus of an employee will be 100% of the basic salary for outstanding performance, 70% of the basic salary for good performance, 40% of the basic salary for average performance, and zero for all other cases. Write an algorithm to calculate and print the total bonus amount to be distributed by the organization. Ref Page 185 Chapter 11: Planning the Computer Program Slide 7/44
  • 8. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Algorithm (Example 2) Step 1: Initialize Total_Bonus and Total_Employees_Checked to zero. (contd…) Step 2: Initialize Bonus and Basic_Salary to zero. Step 3: Take the appraisal form of the next employee. Step 4: Read the employee’s Basic_Salary and Grade. Step 5: If Grade = A, then Bonus = Basic_Salary. Go to Step 8. Step 6: If Grade = B, then Bonus = Basic_Salary x 0.7. Go to Step 8. Step 7: If Grade = C, then Bonus = Basic_Salary x 0.4. Step 8: Add Bonus to Total_Bonus. Step 9: Add 1 to Total_Employees_Checked. Step 10: If Total_Employees_Checked < 100, then go to Step 2. Step 11: Print Total_Bonus. Step 12: Stop. Ref Page 185 Chapter 11: Planning the Computer Program Slide 8/44
  • 9. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Representation of Algorithms § As programs § As flowcharts § As pseudocodes When an algorithm is represented in the form of a programming language, it becomes a program Thus, any program is an algorithm, although the reverse is not true Ref Page 185 Chapter 11: Planning the Computer Program Slide 9/44
  • 10. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Flowchart § Flowchart is a pictorial representation of an algorithm § Uses symbols (boxes of different shapes) that have standardized meanings to denote different types of instructions § Actual instructions are written within the boxes § Boxes are connected by solid lines having arrow marks to indicate the exact sequence in which the instructions are to be executed § Process of drawing a flowchart for an algorithm is called flowcharting Ref Page 186 Chapter 11: Planning the Computer Program Slide 10/44
  • 11. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Basic Flowchart Symbols Terminal Input/Output Processing Decision Flow lines Connectors Ref Page 187 Chapter 11: Planning the Computer Program Slide 11/44
  • 12. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Examples of Decision Symbol No A<B Compare A>B Is I = 10? A&B Yes A=B (a) A two-way branch decision. (b) A three-way branch decision. Ref Page 188 Chapter 11: Planning the Computer Program Slide 12/44
  • 13. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Examples of Decision Symbol (contd…) I=? =0 =1 =2 =3 =4 =5 = Other (c) A multiple-way branch decision. Ref Page 188 Chapter 11: Planning the Computer Program Slide 13/44
  • 14. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Flowchart (Example 3) A student appears in an examination, which consists of total 10 subjects, each subject having maximum marks of 100. The roll number of the student, his/her name, and the marks obtained by him/her in various subjects are supplied as input data. Such a collection of related data items, which is treated as a unit is known as a record. Draw a flowchart for the algorithm to calculate the percentage marks obtained by the student in this examination and then to print it along with his/her roll number and name. Ref Page 188 Chapter 11: Planning the Computer Program Slide 14/44
  • 15. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Flowchart (Example 3) Start (contd…) Read input data Add marks of all subjects giving Total Percentage = Total / 10 Write output data Stop Ref Page 189 Chapter 11: Planning the Computer Program Slide 15/44
  • 16. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Flowchart (Example 4) 50 students of a class appear in the examination of Example 3. Draw a flowchart for the algorithm to calculate and print the percentage marks obtained by each student along with his/her roll number and name. Ref Page 189 Chapter 11: Planning the Computer Program Slide 16/44
  • 17. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Flowchart (Example 4) Start (contd…) Read input data Flowchart for the solution Add marks of all of Example 4 with an subjects giving Total infinite (endless) process loop. Percentage = Total / 10 Write output data Ref Page 190 Chapter 11: Planning the Computer Program Slide 17/44
  • 18. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Flowchart (Example 4) Start (contd…) Count = 0 Read input data Add marks of all subjects giving Total Percentage = Total/10 Write output data Flowchart for the solution Add 1 to Count of Example 4. No Is Count = 50? Yes Stop Ref Page 191 Chapter 11: Planning the Computer Program Slide 18/44
  • 19. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Flowchart (Example 4) Start (contd…) Read input data Yes Is Rollno = 0000000? Generalized flowchart No for the solution of Add marks of all subjects Example 4 using the Stop giving Total concept of trailer record. Here the process loop is Percentage = Total / 10 terminated by detecting a special non-data record. Write output data Ref Page 191 Chapter 11: Planning the Computer Program Slide 19/44
  • 20. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Flowchart (Example 5) For the examination of Example 3, we want to make a list of only those students who have passed (obtained 30% or more marks) in the examination. In the end, we also want to print out the total number of students who have passed. Assuming that the input data of all the students is terminated by a trailer record, which has sentinel value of 9999999 for Rollno, draw a flowchart for the algorithm to do this. Ref Page 192 Chapter 11: Planning the Computer Program Slide 20/44
  • 21. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Flowchart (Example 5) Start (contd…) Count = 0 Read input data Yes Is Rollno = 9999999? No Write Count Add marks of all subjects giving Total Stop Percentage = Total/10 Is Percentage = > 30? No Yes Write output data Add 1 to Count Ref Page 193 Chapter 11: Planning the Computer Program Slide 21/44
  • 22. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Flowchart (Example 6) Suppose the input data of each student for the examination of Example 3 also contains information regarding the sex of the candidate in the field named Sexcode having values M (for male) or F (for female). We want to make a list of only those female students who have passed in second division (obtained 45% or more but less than 60% marks). In the end, we also want to print out the total number of such students. Assuming that the input data of all the students is terminated by a trailer record, which has a sentinel value of Z for Sexcode, draw a flowchart for the algorithm to do this. Ref Page 193 Chapter 11: Planning the Computer Program Slide 22/44
  • 23. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Flowchart (Example 6) Start Count = 0 1 Read input data Yes 2 Is Sexcode = Z? No 1 No Is Sexcode = F? Yes Add marks of all subjects giving Total Percentage = Total / 10 3 Ref Page 195 Chapter 11: Planning the Computer Program Slide 23/44
  • 24. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Flowchart (Example 4) (contd…) 3 No 1 Is Percentage = > 45? Yes 2 No 1 Is Percentage < 60? Write Count Yes Write output data Stop Add 1 to Count 1 Ref Page 195 Chapter 11: Planning the Computer Program Slide 24/44
  • 25. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Levels of Flowchart § Flowchart that outlines the main segments of a program or that shows less details is a macro flowchart § Flowchart with more details is a micro flowchart, or detailed flowchart § There are no set standards on the amount of details that should be provided in a flowchart Ref Page 196 Chapter 11: Planning the Computer Program Slide 25/44
  • 26. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Example of Micro Flowchart Part of a macro 1 flowchart I=1 A micro Flowchart Total = 0 Total = Total + Marks (I) Add marks of all subjects giving Total I=I+1 No Is I > 10? Yes 1 Ref Page 196 Chapter 11: Planning the Computer Program Slide 26/44
  • 27. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Flowcharting Rules § First chart the main line of logic, then incorporate detail § Maintain a consistent level of detail for a given flowchart § Do not chart every detail of the program. A reader who is interested in greater details can refer to the program itself § Words in the flowchart symbols should be common statements and easy to understand Ref Page 196 Chapter 11: Planning the Computer Program Slide 27/44
  • 28. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Flowcharting Rules (contd…) § Be consistent in using names and variables in the flowchart § Go from left to right and top to bottom in constructing flowcharts § Keep the flowchart as simple as possible. Crossing of flow lines should be avoided as far as practicable § If a new flowcharting page is needed, it is recommended that the flowchart be broken at an input or output point. § Properly labeled connectors should be used to link the portions of the flowchart on different pages Ref Page 197 Chapter 11: Planning the Computer Program Slide 28/44
  • 29. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Advantages of Flowchart § Better Communication § Proper program documentation § Efficient coding § Systematic debugging § Systematic testing Ref Page 197 Chapter 11: Planning the Computer Program Slide 29/44
  • 30. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Limitations of Flowchart § Flowcharts are very time consuming and laborious to draw (especially for large complex programs) § Redrawing a flowchart for incorporating changes/ modifications is a tedious task § There are no standards determining the amount of detail that should be included in a flowchart Ref Page 198 Chapter 11: Planning the Computer Program Slide 30/44
  • 31. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Pseudocode § A program planning tool where program logic is written in an ordinary natural language using a structure that resembles computer instructions § “ Pseudo” means imitation or false and “ Code” refers to the instructions written in a programming language. Hence, pseudocode is an imitation of actual computer instructions § Because it emphasizes the design of the program, pseudocode is also called Program Design Language (PDL) Ref Page 198 Chapter 11: Planning the Computer Program Slide 31/44
  • 32. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Basic Logic (Control) Structures Any program logic can be expressed by using only following three simple logic structures: 1. Sequence logic, 2. Selection logic, and 3. Iteration (or looping) logic Programs structured by using only these three logic structures are called structured programs, and the technique of writing such programs is known as structured programming Ref Page 199 Chapter 11: Planning the Computer Program Slide 32/44
  • 33. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sequence Logic It is used for performing instructions one after another in sequence. Process 1 Process 1 Process 2 Process 2 (a) Flowchart (b) Pseudocode Ref Page 199 Chapter 11: Planning the Computer Program Slide 33/44
  • 34. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Selection Logic • Also known as decision logic, it is used for making decisions • Three popularly used selection logic structures are 1. IF…THEN…ELSE 2. IF…THEN 3. CASE Ref Page 200 Chapter 11: Planning the Computer Program Slide 34/44
  • 35. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Selection Logic (IF…THEN…ELSE Structure) Yes No IF Condition IF (condition) THEN Process 1 THEN ELSE ELSE Process 2 Process 1 Process 2 ENDIF (a) Flowchart (b) Pseudocode Ref Page 200 Chapter 11: Planning the Computer Program Slide 35/44
  • 36. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Selection Logic (IF…THEN Structure) Yes No IF (condition) IF Condition THEN THEN Process 1 Process 1 ENDIF (a) Flowchart (b) Pseudocode Ref Page 200 Chapter 11: Planning the Computer Program Slide 36/44
  • 37. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Selection Logic (CASE Structure) Yes Type 1 Process 1 No Yes Type 2 Process 2 CASE Type Case Type 1: Process 1 No Case Type 2: Process 2 Yes Type n Process n Case Type n: Process n No ENDCASE (a) Flowchart (b) Pseudocode Ref Page 201 Chapter 11: Planning the Computer Program Slide 37/44
  • 38. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Iteration (or Looping) Logic § Used to produce loops in program logic when one or more instructions may be executed several times depending on some conditions § Two popularly used iteration logic structures are 1. DO…WHILE 2. REPEAT…UNTIL Ref Page 201 Chapter 11: Planning the Computer Program Slide 38/44
  • 39. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Iteration (or Looping) Logic (DO…WHILE Structure) False Condition? True Process 1 DO WHILE Condition Process 1 Block Process n Process n ENDDO (a) Flowchart (b) Pseudocode Ref Page 202 Chapter 11: Planning the Computer Program Slide 39/44
  • 40. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Iteration (or Looping) Logic (REPEAT…UNTIL Structure) Process 1 REPEAT Process 1 Process n Process n False Condition? UNTIL Condition True (a) Flowchart (b) Pseudocode Ref Page 202 Chapter 11: Planning the Computer Program Slide 40/44
  • 41. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Sample Pseudocode (for Example 6) Set Count to zero Read first student record DO WHILE Sexcode is not equal to Z IF Sexcode = F THEN Calculate Percentage IF Percentage = > 45 THEN IF Percentage < 60 THEN Write output data Add 1 to Count ENDIF ENDIF ENDIF Read next student record ENDDO Write Count Stop Ref Page 203 Chapter 11: Planning the Computer Program Slide 41/44
  • 42. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Advantages of Pseudocode § Converting a pseudocode to a programming language is much more easier than converting a flowchart to a programming language § As compared to a flowchart, it is easier to modify the pseudocode of a program logic when program modifications are necessary § Writing of pseudocode involves much less time and effort than drawing an equivalent flowchart as it has only a few rules to follow Ref Page 204 Chapter 11: Planning the Computer Program Slide 42/44
  • 43. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Limitations of Pseudocode § In case of pseudocode, a graphic representation of program logic is not available § There are no standard rules to follow in using pseudocode § Different programmers use their own style of writing pseudocode and hence communication problem occurs due to lack of standardization § For a beginner, it is more difficult to follow the logic of or write pseudocode, as compared to flowcharting Ref Page 204 Chapter 11: Planning the Computer Program Slide 43/44
  • 44. Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Computer Fundamentals: Pradeep K. Sinha & Priti Sinha Key Words/Phrases § Algorithm § Basic logic structures § Control structures § Flowchart § Iteration logic § Looping logic § Micro flowchart § Macro flowchart § Pseudocode § Program Design Language (PDL) § Sequence logic § Selection logic § Sentinel value § Structured programming § Trailer record Ref Page 204 Chapter 11: Planning the Computer Program Slide 44/44