Page 261 - C++
P. 261

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

                                  6             6, 24, 2, 6
                                  +             6, 24, 8
                                  /             6, 3
                                                3
                          Answer: 3

                          (½ Mark for evaluation till each operator)
                          OR
                          (1 Mark for only writing the Final answer without showing stack
                          status)
             4     (a)    Differentiate between file modes ​r+​ and ​w+​ with respect to Python.               1
                   Ans       ● r+ Opens a file for both reading and writing. The file pointer
                                 placed at the beginning of the file.
                             ● w+ Opens a file for both writing and reading. Overwrites the
                                 existing file if the file exists. If the file does not exist, creates a
                                 new file for reading and writing.

                           (1 mark for one of the correct difference )
                           OR
                           (½ Mark for each correct use of r+ and w+)
                   (b)    Write a method in Python to read lines from a text file DIARY.TXT, and display                                          2
                          those lines, which are starting with an alphabet ‘P’.
                   Ans    def display():
                            file=open('DIARY.TXT','r')
                            line=file.readline()
                            while line:
                              if line[0]=='P' :
                                print line
                              line=file.readline()
                            file.close()   #IGNORE

                          (½ Mark for opening the file)
                          (½ Mark for reading all lines)
                          (½ Mark for checking condition for line starting with P)
                          (½ Mark for displaying line)
                   (c)    Considering the following definition of class COMPANY, write a method in Python                                 3
                          to search and display the content in a pickled file COMPANY.DAT, where CompID is
                          matching with the value ‘1005’.

                          class Company:

                            def __init__(self,CID,NAM):
                                 self.CompID   = CID   #CompID Company ID
                                 self.CName            = NAM  #CName Company Name
                                 self.Turnover = 1000
                            def Display(self):
                              print self.CompID,":",self.CName,":",self.Turnover
                   Ans    import pickle
                          def ques4c( ):
                            f=Factory( )
                            file=open('COMPANY.DAT','rb')
                            try:

                                                     Page #20 of 28
   256   257   258   259   260   261   262   263   264   265   266