Page 165 - Computer
P. 165

school who wants to reward students  represented as shown in Figure 8.11.
            who attain an average mark above 80%.
            Figure 8.10 shows an example of a flow
            chart for rewarding students.                     True   Condition   False           Computer Science
        FOR ONLINE READING ONLY
                     Start

                                                       Statement 1               Statement 2
                   Enter Marks



                                 No
                    Marks >80 ?
                                                       Figure 8.11: Example of IF-THEN-ELSE
                          Yes                                               selection

              Display "Reward a Student"              When  the  IF-THEN-ELSE  structure  is
                                                      encountered:
                                                       (i)   The condition used to make the
                                                             decision is tested.
                       End                             (ii)  If the  condition  is  true,
                                                             the statements  between IF
             Figure 8.10: Flow chart for rewarding students
                                                             and    THEN     are   executed.
                                                             The  ELSE  part  is skipped,  and
            IF…THEN…. ELSE                                   execution  continues with the
            In this structure, the condition is true, if it   statement following ENDIF.
            executes statement 1. If the condition is   (iii)  If the condition is false, the
            false, it will execute the second process        THEN part is skipped. Instead,
            (statement 2). In this case, process 1 or 2      the statements  between ELSE
            will only be implemented depending on            and ENDIF (i.e., the ELSE part
            the given condition. The syntax of IF…           of the structure) are executed,
                                                             and execution continues with the
            THEN…ELSE is shown as follows:
                                                             statement after ENDIF.
                    IF (condition) THEN

                           Statement 1                Example of IF-THEN-ELSE selection
                                                      control structure
                   ELSE
                                                      Write an algorithm using a flowchart that
                           Statement 2                reads two scores of a student, determines

                   ENDIF;                             the  largest score, and print  the  largest
                                                      score with the message that identifies it.
            The     corresponding    flowchart   is   Algorithm: Determining the largest score



                                                  157
              Student’s Book  Form One
   160   161   162   163   164   165   166   167   168   169   170