Page 573 - Cs_withBlue_J_C11_Flipbook
P. 573

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:                                                                                         [10]

                 A disarium number is a number in which the sum of the digits raised to the power of their respective positions is equal
                 to the number itself.
                                    2
                                1
                                        3
                 Example: 135 = 1 + 3  + 5  = 1 + 9 + 125 = 135
                 Hence, 135 is a disarium number.
                 Design a class Disarium to check if a given number is a disarium number or not. Some of the members of the class are
                 given below.

                 Class name : Disarium
                 Data members/instance variables:
                 int num : stores the number
                 int size : stores the size of the number


                 Methods/Member functions:
                 Disarium(int nn) : parameterised constructor to initialise the data members n = nn and size = 0
                 void countDigit( ) : counts the total number of the digits and assigns it to size
                 int sumofDigits(int n, int p) : returns the sum of the digits of the number(n) raised to the power of their respective
                 positions(p)
                 void check( ) : checks whether the number is a disarium number and displays the result with an appropriate message.

                 Specify the class Disarium giving the details of the constructor( ), void countDigit( ), int sumofDigits(int, int) and void
                 check( ). Define the main( ) function to create an object and call the functions accordingly to enable the task.



                 Question 7:                                                                                         [10]
                 A Lower Triangular Matrix is a square matrix in which all the entries above the main diagonal are zero. The entries
                 below or on the main diagonal must be non-zero values.

                 Class name : lowertraiangle

                 Data members/instance variables:
                 int ar[][] : stores the number in array
                 int size : stores the size of the number

                 Methods/Member functions:

                 lowertraingle(int nn) : parameterised constructor to initialise the data member size = nn
                 void input( ): Inputs data in array





                                                                                                                       571
                                                                                                     Model Test Paper  571
   568   569   570   571   572   573   574   575   576   577   578