Page 404 - computer science (868) class 11
P. 404

5.  A class CalSeries has been defined to calculate the sum of the following series.
                               2
                     sum = 1 + x + x  + x  +......x n
                                   3
                     Some of the members of the class are given below:                                         [ISC 2022]
                     Class name                       :   CalSeries
                     Data Members/Instance variables
                     x                                :   Integer to store the value of x
                     n                                :   Integer to store the value of n
                     sum                              :   Integer to store the sum of the series
                     Member Methods/Member functions
                     Calseries()                      :   Default constructor
                     void input()                     :  Accepts the value of x and n respectively
                                                                                     q
                     int power(int p, int q)          :   Returns the power of p raised to q (p ) using the recursive technique
                     void cal()                       :  Calculates the sum of the series by invoking the method power(), and displays
                                                         the result with an appropriate message
                     Specify the class CalSeries giving details of the constructor, void input(), int power(int, int) and void cal(). Define the main()
                    method to create an object and call the member functions accordingly to enable the task.
                  6.  A class ToWord is defined to print the digits of a number in words. Example
                     1567 will be printed as ONE FIVE SIX SEVEN
                     298 will be printed as TWO NINE EIGHT, etc.
                     Some of the members of the class are given below:
                     Class name                       :   ToWord
                     Data Members/Instance variables
                     num                              :   Integer to store the value of num
                     Member Methods/Member functions
                     ToWord()                         :   Default constructor
                     void input()                     :   Accepts the value of num
                     void print(int n)                :  Prints the digits of the numbers in word using the recursive technique
                     Specify the class ToWord giving details of the constructor, void input(), void print(int). Define the main() method to create an
                    object and call the member functions accordingly to enable the task.
                  7.  A class Encode is defined to convert a sentence entered in uppercase to its encoded form as follows:
                     • Vowels are replaced by * (astericks).
                     • Consonants by their next occurring alphabets like B with C, C with D, D with E .... finally Z with A.
                     • Other characters remain unchanged.
                     For example, the sentence COVID 19 will be encoded to D*W*E 19
                     Some of the members of the class are given below:
                     Class name                       :   Encode
                     Data Members/Instance variables
                     sen                              :   To store any sentence
                     esen                             :   To store the encoded sentence
                     Member Methods/Member functions
                     Encode()                         :   Default constructor
                     void input()                     :   To accepts the value of num
                     void change(String s, int p)     :  To encode the sentence  ‘s’  to the form described above  using  the  recursive
                                                         technique and store in variable esen. Here ‘p’ denotes index position
                     Specify the class Encode giving details of the constructor, void input(), void change(String, int). Define the main() method to
                    create an object and call the member functions accordingly to enable the task.
                  8.  A class called Count is defined to find the frequency of the word ‘and’ in a given sentence. For example, if the sentence is:
                     Raj and Ravi went to the concert and had fun.
                     Then, frequency of ‘and’ is 2.
                     Assume that the words can be in upper, lowercase or mixed case.

             402 402  Touchpad Computer Science-XI
   399   400   401   402   403   404   405   406   407   408   409