‹ Back to the paper
[Recursion program] Design a class Spy to check if a number is a Spy number or not. A spy number is…
[Recursion program]
Design a class Spy to check if a number is a Spy number or not. A spy number is a number where the sum of its digits equals the product of its digits. For example, 1124 is a spy number, the sum of its digits is $1+1+2+4=8$ and the product of its digits is $1 \times 1 \times 2 \times 4=8$.
Class name : Spy
Data Members:
num : to store the number
Member methods:
Spy(int nn) : initialize the data member num=nn
int sumOfDigits(int i) : returns the sum of digits of num using recursive technique
int prodOfDigits(int i) : returns the product of digits of num using recursive technique
void check( ) : checks whether the given number is a Spy number or not by invoking the functions sumOfDigits( ) and prodOfDigits( ) and displays appropriate message
Specify the class Spy giving details of the functions int sumOfDigits(int ), void check( ), int prodOfDigits(int). Assume that the data member and constructor are already defined. Define a main method to create an object and call the functions accordingly to enable the task.
Answer
No answer yet.
From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 73.