Page 337 - Computer science 868 Class 12
P. 337

m, n                            :    to store the number of rows and columns
                        Member Functions
                        EqMat(int mm, int nn)           :    initialise the data members m=mm and n=nn
                        void readarray()                :    to enter the elements in the array
                        int check(EqMat P, EqMat Q)     :   checks if the parameterised objects P and Q are equal and returns 1 if true,
                                                            otherwise returns 0.
                        void print()                    :    displays the array elements
                        Define the class and main() function to create objects and call the other functions accordingly to enable the task.
                    7.  You are given a sequence of N integers, which are called as pseudo arithmetic sequences (sequences that are in arithmetic
                       progression).
                        Sequence of N integers : 2, 5, 6, 8, 9, 12
                        We observe that 2 + 12 = 5 + 9 = 6 + 8 = 14
                        The sum of the above sequence can be calculated as 14 × 3 = 42.
                        For a sequence containing an odd number of elements the rule is to double the middle element.
                        For example, 2, 5, 7, 9, 12 = 2 + 12 = 5 + 9 = 7 + 7 = 14. [middle element = 7]
                        14 × 3 = 42
                        A class Pseudoarithmetic determines whether a given sequence is a pseudo-arithmetic sequence or not.
                        The details of the class are given below.
                        Class name                      :    Pseudoarithmetic
                        Data Members/Instance variables
                        n                               :    to store the size of the sequence
                        a[]                             :    integer array to store the sequence of numbers
                        ans, flag                       :   to store the status
                        sum                             :    to store the sum of the sequence of numbers
                        r                               :    to store the sum of the two numbers
                        Member Functions
                        Pseudoarithmetic()              :    default constructor
                        void accept(int nn)             :    to assign nn to n and create an integer array. Fill in the elements of the array
                        boolean check()                 :   returns true if the sequence is a pseudo arithmetic sequence otherwise returns
                                                            false
                        Specify the class Pseudoarithmetic giving the details of the constructor(), void accept(int) and boolean check(). Also, define a
                       main() function to create an object and call the member functions accordingly to enable the task.
                    8.  A class Adder has been defined to add any two accepted valid time.
                        Example:   Time A – 6 hours 35 minutes
                               Time B – 7 hours 45 minutes
                        Their sum is 14 hours 20 minutes
                        class name                      :    Adder
                        Data Members
                        int a[]                         :    int array to hold two elements (ar[0] = hr, ar[1] = min)
                        Member Methods
                        void readtime()                 :   Reads entire elements
                        void addtime(Adder a, Adder b)    :    Adds the time and stores it in the current object
                        void displaytime()              :    Prints the array elements
                    9.  A disarium number is a number in which the sum of the digits to the power of their respective positions is equal to the number
                       itself.
                                    1
                        Example: 135 = 1  + 3  + 5 3
                                       2
                        Hence, 135 is a disarium number.
                        Design a class Disarium to check and print the sum of the number is a disarium number in an array of size 20.
                                                                                                    2
                    10.  Write a program to fill the cells of the matrix in a circular fashion with natural numbers from 1 to n  where n is the size of the
                       square matrix and n is always an odd number.

                                                                                                                       335
                                                                                                              Arrays   335
   332   333   334   335   336   337   338   339   340   341   342