Page 431 - Cs_withBlue_J_C11_Flipbook
P. 431
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.
Some of the members of the class are given below:
Class name : Count
Data Members/Instance variables
line : To store any sentence
Member Methods/Member functions
Count() : Default constructor
void input() : Accepts sentence in variable line
int cal(String s) : Using recursive technique, counts and returns how many times ‘and’ or ‘And’ or
‘AND’ occur in the sentence
void print() : Calls int cal(String) and prints the frequency with an appropriate message
Specify the class Count giving details of the constructor, void input(), int cal(String) and void print(). Define the main() method to
create an object and call the member functions accordingly to enable the task.
9. An array contains Computer Science marks of 50 students of a class. The teacher wants to know how many students of his class
have got 90 and above in his subject. A class Marks is defined to do the same.
Some of the members of the class are given below:
Class name : Marks
Data Nembers/Instance variables
mark[] : An array to store computer marks of 50 students in a class
Member Methods/Member functions
Mark() : Default constructor to initialise the array to 0
void input() : Accepts marks in mark[] of 50 students
int count(int p) : Using recursive technique, counts and returns how many students have got 90%
and above. Here parameters ‘p’ denotes the index position of the array.
void print() : Calls count(int) and prints the array along with the frequency.
Specify the class Marks giving details of the constructor, void input(), int count(int) and void print(). Define the main() method to
create an object and call the member functions accordingly to enable the task.
429
Recursion 429

