Page 307 - C++
P. 307

CBSE AISSCE 2016-2017 Marking Scheme for Computer Science
                                      (Sub Code: 083 Paper Code 91 Outside Delhi)

                            Regno=1
                            Marks=75
                            def __init__(self,r,m):                          #function 1
                                 self.Regno=r
                                 self.Marks=m
                            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.
                   Ans     (i)  Function 1 is the constructor which gets executed automatically as soon as
                               the object of the class is created. Function 2 is a member function which has
                               to be called to assign the values to Regno and Marks.

                           (ii) Function 1      ​E1=Exam(1,95) # Any values in the parameter
                                  Function 2      ​E1.Assign(1,95) # Any values in the parameter

                          (1 mark for correct difference)
                          ( ½ mark for each statement for executing Function 1 and Function 2)
                   (c)    Define a class BOX in Python with 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

                   Ans    class BOX:​ ​# can also be given as  class BOX( ):
                                     # or class BOX(Object):
                            def __init__(self):
                              self.BoxID=101
                              self.Side=10
                              self.Area=0
                            def ExecArea(self):
                              self.Area=self.Side*self.Side
                            def NewBox(self):
                              self.BoxID=input("Enter BoxID")
                              self.Side=input("Enter side")
                              self.ExecArea()               # OR  ExecArea(self)
                            def ViewBox(self):

                                                     Page #17 of 28
   302   303   304   305   306   307   308   309   310   311   312