Page 682 - Computer science 868 Class 12
P. 682

Question 8:
              A class reverse_encode has been defined to perform string related operations on a sentence. The program will execute the following: [10]
              ORIGINAL SENTENCE                              :   INDIA IS A BEAUTIFUL COUNTRY
              CONVERTED TO ASCII FORMAT                      :   7378687365 7383 65 666965858473708576 67798578848289
              NEW SENTENCE                                   :   67798578848289 666965858473708576 65 7383 7378687365
              Some of the members of the class are as follows:
              Class name                                     :  reverse_encode
              Data members/instance variables:
              str                                            :   to store a sentence
              len                                            :   integer to store the length of the sentence
              nstr                                           :   to store the encoded string
              Member functions/methods:
              reverse_encode()                               :   default constructor to initialise data members with legal initial values
              void readstr()                                 :   to accept a sentence in UPPER CASE
              String encode(String)                          :   returns the encoded form of the word given in the parameter.
              void extract()                                 :    Extract each word from the sentence, invokes the method encode(String)
                                                              with the word extracted as parameter, and creates a new sentence in
                                                              converted form in reverse order.
              void display()                                 :   displays the original sentence and the encoded sentence.
              Specify the class reverse_encode, giving the details of the constructor(), void readstr(), void extract() and String encode(String). Define
              the main() function to create an object and call the functions accordingly to enable the task.


                                                            SECTION – C
                                                        Answer any two questions.
                          Each program should be written in such a way that it clearly depicts the logic of the problem stepwise.
                       This can be achieved by using comments in the program and mnemonic names or pseudo codes for algorithms.
               The programs must be written in Java and the algorithms must be written in general/standard form, wherever required/specified.
                                                       (Flowcharts are not required.)


              Question 9.
              Book_Self is a kind of data structure which can store atmost 20 books. The Book_Self restriction is that a book can be kept into the
              Book_Self or removed only at one, i.e. on the top.
              The class Book_Self has the following details:
              class name                                     :  Book_Self
              Data members/instance variables
              book[]    array of string of maximum 20 locations to store books
              name     string variable to store name of book
              limit     integers as maximum capacity of the array
              top      integer to indicate topmost book into the Book_Self
              Member functions/methods
              Book_Self(int nx)                              :   a constructor a constructor to assign nx to limit and -1 to top and to store
                                                              blank in the array book
              void dispList()                                :  to display list of books in the Book_Self
              void put_on_selve()                            :   input name of the book into variable name and adds it on the top of the
                                                              Book_Self if there is a empty location, else prints message “No space,
                                                              Book_Self will overflow”
              void remove_from_selve()                       :    if Book_Self is empty prints a message “No Books are there" else removes
                                                              a book from the top of the Book_Self and prints the name of the book.
              Specify the class Book_Self giving the details of the functions put_on_self() and remove_from_self(). Assume all the other other functions
              are written for you. You do not have to write the main() function.



                680680  Touchpad Computer Science-XII
   677   678   679   680   681   682   683   684   685   686