Page 97 - Computer Science Class 11 With Functions
P. 97

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 = True                                                              eligible = False


                                                                       True
                                                                  age = 18
                                                                eligible = True





                          Stop

                                       Fig 4.5: Flowchart representation to compute the age in years







                                                                                                Problem Solving  95
   92   93   94   95   96   97   98   99   100   101   102