Page 437 - Computer science 868 Class 12
P. 437
14. An array contains Computer Science marks of 50 students of a class. The teacher wants to know how many students of his/her
class has got 90 and above in the subject taught by him/her. A class Marks is defined to do the same.
Some of the members of the class are given below.
Class name : Marks
Data Members/Instance variables
mark[] : an array to store computer marks of 50 students in a class
Methods/Member functions
Mark() : default constructor to initialise the array to 0
void input() : to accept 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 index position of the array
void print() : calls count(int) and prints the array along with the frequency
Specify the class Transpose 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.
15. A class Transpose is defined to generate the transpose of a matrix. The transpose of a matrix is obtained by interchanging its rows
into columns or columns into rows
For example, if size = 3 and matrix a[][] is
1 2 3
4 5 6
7 8 9
then its transpose b[][] will be
1 4 7
2 5 8
3 6 9
Some of the members of the class are given below.
Class name : Transpose
Data Members/Instance variables
s : integer to store size of matrix
a[][] : integer two dimensional matrix
b[][] : integer matrix to store the transpose of a
Methods/Member functions
Transpose(int ss) : initialise s to ss and declare the matrix
void input() : to accept numbers in matrix a[][]
void generate(int r, int c) : using recursive technique, generate the transpose matrix in b[][], here parameters
‘r’ and ‘c’ denotes row and column position respectively
void print() : calls generate(int,int) and then prints the transpose matrix b[][]
Specify the class Transpose giving details of the constructor, void input(), int void generate(int, int) and void print(). Define the
main() method to create an object and call the member functions accordingly to enable the task.
16. A class called Word is defined to count number of words in a sentence. The words in a sentence can be separated by space or
comma or question mark and full stop will be the terminating character. The class description is given below:
Data Members
String s : to store sentence
int len : to store length of the sentence
Member Methods
void read() : accepts any sentence
int count(int l) : using recursive technique counts and returns number of words in the sentence
void show() : calls count(int) and prints word count
static void main() : creates object and calls other methods
435
Recursion 435

