Page 269 - Computer science 868 Class 12
P. 269

return-1;
                       }
                      (i)   What is the expression or statement at ?1?
                      (ii)   What is the expression or statement at ?2?
                      (iii)   What is the expression or statement at ?3?
                      (iv)  What is the expression or statement at ?4?
                      (v)  What is the expression or statement at ?5?
                    24.  The following is a part of some class. What will be the output of the function mymethod() when the value of the counter is equal
                       to 3? Show the dry run/working.
                       void mymethod (int counter)
                       {
                       if (counter == 0)
                       System.out. println(" ");
                       else
                       {
                       System.out.println ("Hello" +counter);
                       mymethod (--counter);
                       System.out.println (" " +counter);
                       }
                       }
                    25.  The following function Mystery() is a part of some class. What will be the function Mystery() return when the values of num=43629,
                       x=3 and y=4? Show the dry run/working.
                       int Mystery (int num, int x, int y)
                       {
                       if(num<10)
                       return num;
                       else
                       {
                       int z = num % 10;
                       if(z%2 == 0)
                       return z*x + Mystery (num/10, x, y);
                       else
                       return z*y + Mystery(num/10, x, y);
                       }
                       }
                 D.  Programs to be solved:
                    1.  A class ConsChange has been defined with the following details.
                        Class name                   :  ConsChange
                        Data Members/Instance variables
                        word                         :   stores the word
                        len                          :   stores the length of the word
                        Member Functions/Methods
                        ConsChange()                 :   default constructor
                        void readword()              :   accepts the word in lowercase
                       void shiftcons()              :     shifts  all  the  consonants  of  the  word  at  the  beginning  followed  by  the  vowels
                                                        (e.g., spoon becomes spnoo)
                        void changeword()            :    changes the case of all  occurring  consonants  of  the  shifted  word  to  uppercase,
                                                        (e.g., spnoo becomes SPNoo)
                        void show()                  :   displays the original word, shifted word and the changed word
                        Specify the class ConsChange giving the details of the constructor(), void readword(), void shiftcons(), void changeword() and void
                       show(). Define the main() function to create an object and call the functions accordingly to enable the task.



                                                                                                                       267
                                                                                                            Methods    267
   264   265   266   267   268   269   270   271   272   273   274