Page 681 - Computer science 868 Class 12
P. 681
SECTION – B
Answer any two questions.
Each program should be written in such a way that it clearly depicts the logic of the problem.
This can be achieved by using mnemonic names and comments in the program.
(Flowcharts and Algorithms are not required.)
The programs must be written in Java.
Question 6.
Class name : Unique
Data members/instance variables:
num : to store a positive integer number
count : couints the number of digits in check_digit(int)
Methods/Member functions:
Unique() : default constructor to initialize the data member
void input_num() : to accept a positive integer number
int count_digit(int d) : returns the number of digits stored in d from num using recursive
void check() : to check whether the given number is an Unique number or not depending
on the value returned from count_digit(int). If the value returned is more
than 1, then it is not an Unique Digit.
Specify the class Unique giving details of the constructor(), void input_num(), int count_digit(int) and void check(). Define a main()
function to create an object and call all the functions accordingly to enable the task.
Question 7:
A class Happy contains a two-dimensional array of order [m × n]. The maximum values possible for both ‘m’ and ‘n’ is 20. Design a class
Happy to fill the array with the first (m × n) Happy numbers in Rowwise.
The details of the members of the class are given below:
A happy number is a number in which the eventual sum of the square of the digits of the number is equal to 1. [10]
Example:
28 = (2)∧2 + (8)∧2 = 4 + 64 = 68
68 = (6)∧2 + (8)∧2 = 36 + 64 = 100
100 = (1)∧2 + (0)∧2 + (0)∧2 = 1 + 0 + 0 = 1
Hence, 28 is a happy number.
Example:
12 = (1)∧2 + (2)∧2 = 1 + 4 = 5
Hence, 12 is not a happy number.
Design a class Happy to fill first m × n happy numbers in the array row wise. Some of the members of the class are given below:
Class name : Happy
Data Members/instance variables:
arr[][] : integer array to store the Happy numbers row wise
m : integer to store the number of rows
n : integer to store the number of columns
Happy(int mm, int nn) : to initialise the size of the matrix, m=mm and n=nn
boolean ishappy(int) : checks if the parameterised number is a happy number and returns true
if it is a Happy number else returns false.
void fill() : to fill the elements of the array with the first (m × n) Happy numbers
rowwise by invoking the ishappy(int) method.
void display() : to display the array in a matrix form
Specify the class Happy giving details of the Happy(int mm, int nn), boolean ishappy(int), void fill () and void display(). Also define a main()
function to create an object and call the methods.
679
ISC Specimen Question Paper 679

