Page 109 - Computer Science V2.0 Class 11
P. 109

Next, we give a pseudocode to compute the age in years. For the sake of simplicity, we assume that eligibility to vote
                 is determined on 01 January of the year. We will assume that day.DD, day.MM, and day.YYYY denotes the day,
                 month, and year for the date day. If a person is eligible to vote, we set eligible as true and false otherwise.
                 Input: Date of birth—DOB
                 Process: If the difference between the current year and the year of date of birth is greater than 18, eligible is set
                 to True.
                 Output: Eligible—True, Not Eligible—False



                 today ← Today's date from System

                 if (today.YYYY - DOB.YYYY) > 18 then
                     age ← today.YYYY - DOB.YYYY
                     eligible ← True
                 else if (today.YYYY - DOB.YYYY) equals 18 then
                     if DOB.DD equals 1 and DOB.MM equals 1 then

                         age ← 18
                         eligible ← True
                     else

                         not eligible ← False

                               Start




                          today = today's date





                                                    False
                        today.YYYY–DOB.YYYY>18                   today.YYYY–DOB.YYYY=18



                                  True                                      True


                       age = today.YYYY–DOB.YYYY                DOB.MM = 1 and DOB.DD = 1    False       eligible = False
                            eligible = True

                                                                            True

                                                                       age = 18
                                                                     eligible = True





                               Stop

                                            Fig 4.5: Flowchart representation to compute the age in years






                                                                                                     Problem Solving  95
   104   105   106   107   108   109   110   111   112   113   114