KEMBAR78
Recursion ISC Questions | PDF | Programming | Constructor (Object Oriented Programming)
0% found this document useful (0 votes)
14 views6 pages

Recursion ISC Questions

Uploaded by

tejpreetkaur496
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views6 pages

Recursion ISC Questions

Uploaded by

tejpreetkaur496
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

J H TARAPORE SCHOOL

SECOND TERM (2025-26)


COMPUTER SCIENCE
WORKSHEET 1
RECURSION
RECURSION
Question 1
Design a class NumDude to check if a given number is a Dudency number or not. (A Dudency
number is a positive integer is a perfect cube, such that the sum of its digits is equal to the cube
root of the number.)
Example: 5832 = (5+8+3+2)³ = (18)³ = 5832, thus 5832 is a Dudency number.
The details of the class are given below:
Class name: NumDude
Data members/instance variables:
num : to store a positive integer number.
Member functions/methods:
NumDude() : constructor to initialise the data members with legal initial values.
void input() : to accept a positive integer number in num.
int sumDigits(int x) : returns the sum of digits of the number 'x' using recursive technique.
void isDude() : checks whether the given number is a Dudency number by invoking the
recursive function int sumDigits(int) and displays the result with an appropriate message.
Specify the class NumDude giving the details of the constructor and methods void input(), int
sumDigits(int) and void isDude(). Define a main() function to create an object and call the
functions accordingly to enable the task.
Question 2 [ISC 2020, 2015]
Design a class BinSearch to search for a particular value in an array.
The details of the members of the class are given below:
Class name: BinSearch
Data members/instance variables:
arr[] : to store integer elements.
n : integer to store the size of the array.
Member functions/methods:
BinSearch(int nn) : parameterised constructor to initialise n=nn.
void fillarray() : to enter the elements in the array.
void sort() : sorts the array in ascending order using any standard sorting technique.
int bin_search(int l, int u, int v) : searches for the value 'v' using binary search and recursive
technique and returns its location if found otherwise returns -1.
Specify the class BinSearch giving details of the constructor and functions void fillarray(), void
sort() and int bin_search(int, int, int). Define a main() function to an create object and call the
methods accordingly to enable the task.
Question 3 [ISC 2019]
Design a class ArmNum to check if a given number is an Armstrong number or not. (A number
is said to be Armstrong if sum of its digits raised to the power of length of the number is equal to
the number).
Examples:
371 = 3³ + 7³ + 1³
1634 = 1⁴ + 6⁴ + 3⁴ + 4⁴
54748 = 5⁵ + 4⁵ + 7⁵ + 4⁵ + 8⁵
Thus 371, 1634 and 54748 are all the examples of Armstrong numbers.
The details of the class are given below:
Class name: ArmNum
Data members/instance variables:
n : to store the number.
l : to store the length of the number.
Member functions/methods:
ArmNum(int nn) ​ : parameterised constructor to initialise the data members n= nn

int sum_pow(int i)​ : returns the sum of each digit raised to the power of the length of the
number using recursive technique
void isArmstrong() ​ :checks whether the given number is an Armstrong number by invoking
the function sum_pow() and displays the result with a message
Specify the class ArmNum giving the details of constructor and methods int sum_pow(int) and
void isArmstrong(). Define a main() function to create an object and call the functions
accordingly to enable the task.

Question 4[ISC 2018]


Design a class Perfect to check if a given number is a perfect number or not. A number is said to
be perfect if the sum of the factors of the number excluding itself is equal to the original number.
For example: Input 6. Its factors excluding itself = 1, 2, 3, and its sum 1+2+3 = 6. Hence 6 is a
perfect number.

Class name: Perfect


Data members/instance variables:
num: to store an integer number.
Member functions/methods:
Perfect(int nn): parameterised constructor to initialise the data member num.
int sum_of_factors(int i): returns the sum of the factors of the number (sum), excluding itself,
using Recursive Technique.
void check(): checks whether the number (num) is a perfect number by invoking the recursive
function sum_of_factors() and display the result with an appropriate message.
Specify the class Perfect giving the details of the Define a main() function to create an object and
call the functions accordingly to enable the task. constructor and methods int sum_of_factors(int)
and void check().

Question 5[ISC 2017]


A class Palin has been defined to check whether a positive number is a Palindrome number or
not. The number 'N' is palindrome if the original number and its reverse are same.
The details of the class are given below:
Class name: Palin
Data members/instance variables:
num​ ​ : to store an integer number.
revnum​ : integer to store the reverse of the number.
Member functions/methods:
Palin()​​ : constructor to initialise the data members with legal values.
void accept()​ : to accept the number.
int Reverse(int y): reverses the parameterized argument 'y' and stores it in 'revnum' using the
Recursive Technique.
void check()​ : checks whether the number (num) is a Palindrome number by invoking the
recursive function Reverse() and display the result with an appropriate message.
Specify the class Palin giving the details of constructor and methods void accept(), int
Reverse(int) and void check(). Define a main() function to create an object and call the functions
accordingly to enable the task.

Question 6​ [ISC 2016]


Disarium number is a number in which the sum of the digits to the power of their respective
position is equal to the number itself.
Example: 135 = 1¹ + 3² + 5³. Hence 135 is a disarium number.
Design a class Disarium to check if a given number is disarium number or not
The details of the class are given below
Class name: Disarium
Data members/instance variables:
num: to store an integer number.
size: integer to store the size of the number.
Member functions/methods:
Disarium(int n)​ ​ : parameterised constructor to initialise the data num and size=0.
void countDigits()​ ​ : counts the total number of digits and assigns it to size.
int sumofDigits(int n, int p)​ : returns the sum of the digits of the number (n) to the power of
their respective positions (p) using the Recursive Technique.
void check()​ ​ ​ : checks whether the number (num) is a disarium number and
display the result with an appropriate message.
Specify the class Disarium giving the details of constructor and methods void countDigits(), int
sumofDigits(int, int), void check(). Define a main() function to create an object and call the
functions accordingly to enable the task.
Question 7 [ISC 2014]
A class SeriesSum is designed to calculate the sum of the following series: Sum = x/1! + x^2/2!
+ x^3/3! + ... + x^n/(n+1)! The members of the class are given below:
Class name: SeriesSum
Data members/instance variables:
n: to store an integer number.
x: to store number of terms.
sum: double variable to store the sum of the series.
Member functions/methods:
SeriesSum(int xx, int nn)​ : constructor to assign parameters n=nn and x=xx.
double findfact(int m)​​ : to return the factorial of 'm' using the Recursive technique.
double findpower(int x, int y): to return 'x' raised to the power 'y' using the Recursive technique.
void calculate()​ ​ : to calculate the sum of the series by invoking the two recursive
functions respectively.
void display()​ ​ ​ : to print the sum of the series stored in variable sum.
(a) Specify the class SeriesSum giving the details of constructor and functions double
findfact(int), double findpower(int), void calculate() and void display(). Define a main() function
to create an object and call the methods accordingly to enable the task.
(b) State the two differences between iteration and recursion.
Question 8 [ISC 2013]
An emirp number is a number which is prime backwards and forwards. Example: 13 and its
reverse 31 are both primes, thus 13 is an emirp number. Design a class Emirp to check if a given
number is Emirp or not. The details of the class are given below:
Class name: Emirp
Data members/Instance variables:
n: integer to store a number.
rev: stores the reverse of the number.
f: stores the divisor.
Member functions/ methods:
Emirp(int nn)​ ​ : constructor to assign n=nn, rev=0 and f=2.
int isprime(int a)​ : check if the number is prime using the Recursive Technique and return 1
if prime otherwise return 0.
void isEmirp()​​ : reverse the given number and check if both the original number and the
reversed number are prime, by invoking the function isprime(). If both are prime, then display
the result with an appropriate message.
Specify the class Emirp giving details of the constructor and functions int isprime(int) and void
isEmirp(). Define a main() function to create an object and call the methods accordingly.
Question 9
A happy number is a number in which the eventual sum of the square of the digits is equal to 1.
Example 1: 28 = (2²) + (8²) = 4+64 = 68
68 = (6²) + (8²) = 36+64 = 100
100 = (1²) + (0²) + (0²) = 1+0+0 = 1
Hence, 28 is a Happy number
Example 2: 12 = (1²) + (2²) = 1+4 = 5
Hence, 12 is not a Happy number
Design a class Happy to check if a given number is a happy number.
The details of the class are given below:
Class name : Happy
Data members/instance variables :
n : integer to store a number.
Member functions/methods:
Happy() ​ ​ : constructor to assign n=0.
void getnum(int nn)​ : to assign the parameter value to n.
int sum_sq_digits(int x) : returns the sum of the square of the digits of the number x, using the
Recursive Technique.
void ishappy()​​ : checks if the given number is a happy number by calling the recursive
function int sum_sq_digits(int) and displays the result with an appropriate message.
Specify the class Happy giving details of the constructor and functions void getnum(int), int
sum_sq_digits(int) and void ishappy(). Define a main() function to create an object and call the
methods accordingly.

Question 10
A class DeciOct has been defined to convert a decimal number to its equivalent octal number.
The details of the class are given below:
Class name : DeciOct
Data members/instance variables :
n : integer to store a decimal number.
oct : stores the octal equivalent of n.
Member functions/methods:
DeciOct()​ ​ : constructor to assign n=0 and oct=0.
void getnum(int nn)​ : to assign nn.
void deci_oct() ​ : calculates the octal equivalent of 'n' and stores it in 'oct' using the
Recursive Technique.
void show() ​ ​ : displays the decimal number 'n' and calls the recursive function
deci_oct() and displays its octal equivalent.
Specify the class DeciOct giving details of the constructor and functions void getnum(int), void
deci_oct() and void show(). Define a main() function to create an object and call the functions
accordingly to enable the task.

You might also like