Page 472 - Cs_withBlue_J_C11_Flipbook
P. 472

Example: 7 - as its binary 111 as its 1’s count = 3
                     14 - as its binary 1110 as its 1’s count = 3
                     The class description is given below/
                    Package                                       :  Green
                    Class name                                    :  Odious
                    Data Members
                    int num, bin                                  :  Stores number and its binary equivalent
                    Member Methods
                    void accept()                                 :  Accepts a positive integer decimal number
                    int tobin(int a)                              :  Converts the decimal number to binary and returns the result

                    void check()                                  :  Checks if the number is an Odious number or not using method
                                                                     count() in class CountDig of package Comprac
                    Define the above classes and also write the main method to execute the same.
                  2.  Write a program to create a package Comprac containing class SumDig having the following specifications.
                    Package                                       :  Comprac
                    Class name                                    :  SumDig
                    Data Members
                    int n                                         :  Stores number
                    Member Methods
                    SumDig(int x)                                 :  Constructor to assign the data members
                    int sumofdig()                                :  Returns the sum of the digits of the number
                      Write a second class Magic in package Green to import class SumDig of package Comprac and use the method sumofdig() to check
                    if a number is a Magic number or not. A magic number is one in which the ultimate sum of the digits of the number is equal to
                    one.
                      Example, say number is 874
                     Sum of digits = 4 + 7 + 8 = 19
                     Sum of digits of 19 = 1 + 9 = 10
                     Sum of digits of 10 = 1 + 0 = 1
                     Since, further digit extraction is not possible and the final sum = 1 then 874 is a magic number.
                     The class description is given below.
                    Package                                       :  Green
                    Class name                                    :  Magic
                    Data Members
                    int num                                       :  Stores number
                    Member Methods
                    void accept()                                 :  Accepts a positive integer decimal number
                    void check()                                  :  Checks if  the number is  an  magic number or not  by using
                                                                     sumofdig() of class SumDig in package Comprac
                      Define the above classes and also write the main method to execute the same.
                  3.  Write a program to create a package ComPack containing class Sort having the following specifications.
                    Package                                      :  ComPack
                    Class name                                   :  Sort
                    Data Members
                    int n                                        :  Size of the array
                    int a[]                                      :  Integer array
                    Member Methods
                    ComPack (int x, int y[])                     :  Constructor to assign the data members
                    int [] bubble()                              :  Sorts the array using bubble sort technique in ascending order
                                                                    and returns the sorted array



                470470  Touchpad Computer Science-XI
   467   468   469   470   471   472   473   474   475   476   477