Page 435 - Computer science 868 Class 12
P. 435
String tobinary(int a) : returns the binary equivalent of number ‘a’ as String using recursive technique
int countones(String s) : using recursive technique, returns the frequency of ‘1’ in its binary form ‘s’
expressed as String
void isEvil() : calls tobinary(int) and countones(String) and prints if the number is an evil
number or not
Specify the class Evilnum giving details of the methods void getnum(), String tobinary(int ) and int countones( String) and void
isEvil (). Also define the main() function to create an object and call the functions accordingly to enable the task.
8. A number is said to be Krishnamurthy if the sum of factorial of it's digits is equal to that number. For example Number = 145
= 1! + 4! + 5! = 1 + 24 + 120 = 145
A class called Kmurthy is defined to check if a given number is Krishnamurthy number or not. The details of the class is given
below:
Class name : Kmurthy
Data Members/Instance variables
num : to store the number
Methods/Member functions
void getnum() : accept number in num from the user
int factorial(int a) : returns the factorial of 'a' using recursive technique
int sumfact(int x) : calls method int factorial(int) and using recursive technique calculates and returns
sum of factorial of the digits of number ‘num’
void check () : calls int sumfact(int x) and checks if the given number is a Krishnamurthy number
or not
Specify the class Kmurthy giving details of the methods void getnum(), int factorial(int )and int sumfact(int ) and void check (). Also
define the main() function to create an object and call the functions accordingly to enable the task.
9. Monodigit numbers are numbers consisting of a single repeating digit, e.g. 77, 999, 8888 etc.
A class called Mono is defined to check if a given number is monodigit number or not. The details of the class is given
below:
Class name : Mono
Data Members/Instance variables
num : to store the number
Methods/Member functions
void getnum() : accept number in num from the user
boolean check (int n, int d) : using recursive technique checks if the number ‘n’ whose last digit is ‘d’ is a mono
digit number or not and returns true or false accordingly
void print() : calls boolean check(int,int) and prints appropriate message
Specify the class Mono giving details of the methods void getnum(), boolean check (int, int ) and void print (). Also define the
main() function to create an object and call the functions accordingly to enable the task.
10. A class CalSeries has been defined to calculate the sum of the series sum = 1 + x + x + x + ...... x n
3
2
Some of the members of the class are given below. [ISC 2022]
Class name : CalSeries
Data Members/Instance variables
x : integer to store value of x
n : integer to store value of n
sum : integer to store sum of the series
Methods/Member functions
Calseries() : default constructor
void input() : to accept the value of x and n respectively
q
int power(int p, int q) : returns the power of p raised to q (p ) using recursive technique.
void cal() : calculates the sum of the series by invoking the method power(), and displays the
result with an appropriate message
433
Recursion 433

