Page 260 - C++
P. 260

CBSE AISSCE 2016-2017 Marking Scheme for Computer Science
                                         (Sub Code: 083 Paper Code 91/1 Delhi)
                   (c)    Write Addnew(Book) and Remove(Book) methods in Python to Add a new Book and                                    4
                          Remove a Book from a List of Books, considering them to act as PUSH and POP
                          operations of the data structure Stack.

                   Ans    class stack:
                            Book=[]
                            def Addnew(self):
                              Name=input("Enter Book Name :")
                              stack.Book.append(Name)
                            def Remove(self):
                              if (stack.Book==[]):
                                print "Stack Empty"
                              else:
                                print "Deleted Book is : ",stack.Book.pop()
                          ( ½ mark for Addnew header)
                          ( ½ mark for accepting a Book from user)
                          ( 1 mark for adding value in list)
                          ( ½ mark for Remove header)
                          ( ½ mark for checking empty list condition)
                          ( ½ mark for displaying Book getting removed)
                          ( ½ mark for removing Book)
                          NOTE:
                          Marks not to be deducted for methods written without using a class
                   (d)    Write definition of a Method AFIND(CITIES) to display all the city names from a list                                         2

                          of CITIES, which are starting with alphabet A.
                          For example:
                          If the list CITIES contains
                          ["AHMEDABAD","CHENNAI","NEW DELHI","AMRITSAR","AGRA"]

                          The following should get displayed
                          AHEMDABAD
                          AMRITSAR
                          AGRA
                   Ans    def AFIND(CITIES):
                            for i in CITIES:
                              if i[0]=='A':

                                 print i
                          ( ½ mark function header)
                          ( ½ mark for loop)
                          ( ½ mark for checking condition of first letter A)
                          ( ½ mark for displaying value)

                   (e)    Evaluate the following Postfix notation of expression:                               2
                          2,3,*,24,2,6,+,/,-

                   Ans
                                  Element   Stack Contents
                                  2             2
                                  3             2, 3
                                  *             6
                                  24            6, 24
                                  2             6, 24, 2


                                                     Page #19 of 28
   255   256   257   258   259   260   261   262   263   264   265