Page 271 - Computer science 868 Class 12
P. 271

Member Methods/Member functions
                        Perfect (int nn)             :    parameterised constructor to initialise the data member num=nn
                        int sum_of_factors(int i)    :   returns the sum of the factors of the number(num), excluding itself using a recursive
                                                        technique
                        void check()                 :   checks  whether  the  given  number  is  perfect  by  invoking  the  function  sum_of_
                                                        factors() and displays the result with an appropriate message
                        Specify the class Perfect giving details of the constructor(), int sum_of_factors(int) and void check(). Define a main() function to
                       create an object and call the functions accordingly to enable the task.
                    6.  The coordinates of a point P on a two-dimensional plane can be represented by P(x, y) with x as the x-coordinate and y as the
                       y-coordinate. The coordinates of the midpoint of two points P1(x1, y1) and P2(x2, y2) can be calculated as P(x, y) where:
                        x = (x1 + x2)/2, y = (y1 + y2)/2
                        Design a class Point with the following details.
                        Class name                   :    Point
                        Data Members/Instance variables
                        x                            :    stores the x-coordinate
                        y                            :    stores the y-coordinate
                        Member Functions
                        Point ()                     :    constructor to initialise x = 0, y = 0
                        void readpoint ()            :    accepts the coordinates x and y of a point
                        Point midpoint (Point A, Point B)   :    calculates and returns the midpoint of the two points A and B
                        void displaypoint ()         :    displays the coordinates of a point
                        Specify the class Point giving details of the constructor (), void readpoint (), Point midpoint (Point, Point) and void displaypoint ()
                       along with the main () function to create an object and call the functions accordingly to calculate the midpoint between any two
                       given points.
                    7.  A class Combine contains an array of integers that combines two arrays into a single array including the duplicate elements, if any,
                       and sorts the combined array. Some of the members of the class are given below.
                        Class name                   :    Combine
                        Data Members/Instance variables
                        com[]                        :    integer array
                        size                         :    size of the array
                        Member Functions/Methods
                        Combine(int nn)              :    parameterised constructor to assign size = nn
                        void inputarray()            :    accepts the array elements
                        void sort()                  :   sorts the elements of the combined array in ascending order using the selection sort
                                                        technique
                        void mix(Combine A, Combine B)   :   combines the parameterised object arrays and stores the result in the current object
                                                        array along with duplicate elements, if any
                        void display()               :    displays the array elements
                        Specify the class Combine giving details of the constructor (int), void inputarray(), void sort(), void mix (Combine, Combine) and
                       void display (). Also, define the main() function to create an object and call the methods accordingly to enable the task.
                    8.  A class Mixer has been defined to merge two sorted integer arrays in ascending order. Some of the members of the class are given
                       below.
                        Class name                   :    Mixer
                        Data Members/Instance variables
                        int arr[]                    :    to store the elements of an array
                        int n                        :    to store the size of an array
                        Member Functions
                        Mixer(int nn)                :    constructor to assign n=nn
                        void accept()                :   to accept the elements of the array in ascending order without any duplicates
                        Mixer mix (Mixer A)          :   to merge the current object array elements with the parameterised array elements
                                                        and return the resultant object


                                                                                                                       269
                                                                                                            Methods    269
   266   267   268   269   270   271   272   273   274   275   276