Page 403 - computer science (868) class 11
P. 403

int countdigit(int a)       :  Counts and returns the number of digits in ‘a’ using the recursive technique
                                                                                        th
                        int sumpower(int a, int p)   :   Using recursive technique, returns sum of p  power of the digits of the number stored
                                                       in variable a
                        void isArmstrong()          :    Calls countdigit(int) and sumpower(int, int) and prints if the number is an Armstrong
                                                       number or not
                        Specify the class Armstrong giving details of the methods void getnum(), int countdigit(int) and int sumpower(int,int) and void
                       isArmstrong(). Also define the main() function to create an object and call the functions accordingly to enable the task.
                    2.  The Evil number is a special positive whole number that has an even number of 1’s in its binary equivalent.
                        6 is an evil number as its binary equivalent 110 has 2 1’s.
                        9 is an evil number as its binary value 1001 has 2 1’s.
                        15 is an evil number as its binary value 1111 has 4 1’s.
                        A class called Evilnum is defined to check if a number is an evil number or not. Some of the members of the class are given below:
                        Class name                  :   Evilnum
                        Data Members/Instance variables
                        num                         :  To store the number
                        Member Methods/Member functions
                        void getnum()               :  Accepts number in num from the user
                        String tobinary(int a)      :  Returns the binary equivalent of number ‘a’ as String using the 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() method to create an object and call the methods accordingly to enable the task.
                    3.  A number is said to be Krishnamurthy if the sum of factorial of its 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 detail of the class is given below:
                        Class name                      :   Kmurthy
                        Data Members/instance variables
                        num                             :   To store the number
                        Member Methods/Member functions
                        void getnum()                   :   Accepts 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 the sum of factorial of the digits of number ‘X’
                        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.
                    4.  Monodigit numbers are the 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 detail of the class is given below:
                        Class name                      :   Mono
                        Data Members/Instance variables
                        num                             :   To store the number
                        Member Methods/Member functions
                        void getnum()                   :   Accepts 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.




                                                                                                                       401
                                                                                                           Recursion   401
   398   399   400   401   402   403   404   405   406   407   408