Page 235 - C++
P. 235

I1=ITEM()
                         I2=ITEM(100,"Eraser",100)
                         I3=ITEM(102,"Sharpener")
                         I1.Buy(10)
                         I2.Sell(25)

                         I3.Buy(75)
                         I3.ShowStock()
                         I1.ShowStock()
                         I2.ShowStock()

                   (f)   What are the possible outcome(s) executed from the following code ? Also specify
                         the maximum and minimum values that can be assigned to variable N.               2
                         import random
                         SIDES=["EAST","WEST","NORTH","SOUTH"];
                         N=random.randint(1,3)
                         OUT=""
                         for I in range(N,1,–1):
                              OUT=OUT+SIDES[I]
                         print OUT
                         (i)  SOUTHNORTH  (ii)  SOUTHNORTHWEST

                         (iii)  SOUTH           (iv)  EASTWESTNORTH


             2.    (a)   List four characteristics of Object Oriented Programming.                        2

                   (b)  class Test:                                                                       2
                              rollno=1
                              marks=75
                              def_init_(self,r,m):                           #function 1
                                  self.rollno=r
                                  self.marks=m
                              def assign(self,r,m):                          #function 2
                                  rollno = n
                                  marks = m
                              def check(self):                               #function 3
                                  print self.rollno,self.marks
                              print rollno,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.


             91/1                                          10
   230   231   232   233   234   235   236   237   238   239   240