Page 284 - C++
P. 284

def Assign(self,r,m):                        #function 2
                         Regno = r

                         Marks = m

                     def Check(self):                             #function 3

                         print self.Regno, self.Marks
                         print Regno, Marks

                   (i)     In the above class definition, both the functions — function 1
                           as well  as function 2  have  similar  definition.  How  are  they
                           different in execution ?
                   (ii)    Write statements to execute function 1 and function 2.


           (c)     Define a class BOX in Python with the following specifications :                4

                   Instance Attributes

                   - BoxID           # Numeric value with a default value 101
                   - Side            # Numeric value with a default value 10
                   - Area            # Numeric value with a default value 0


                   Methods :
                   - ExecArea()  # Method to calculate Area as

                                     # Side * Side
                   - NewBox()        # Method to allow user to enter values of
                                     # BoxID and Side. It should also

                                     # Call ExecArea Method
                   - ViewBox()       # Method to display all the Attributes


           (d)     Differentiate between static and dynamic binding in Python ? Give
                   suitable examples of each.                                                      2

           (e)     Write  two  methods  in  Python  using  the  concept  of  Function
                   Overloading (Polymorphism) to perform the following operations :                2

                   (i)     A function having one argument as Radius, to calculate Area
                           of Circle as 3.14*Radius*Radius.

                   (ii)    A  function  having  two  arguments  as  Base  and  Height,  to
                           calculate Area of right-angled triangle as 0.5*Base* Height.

      91                                            14
   279   280   281   282   283   284   285   286   287   288   289