Page 432 - Cs_withBlue_J_C11_Flipbook
P. 432

10.  A class Transpose is defined to generate the transpose of a matrix. The transpose of a matrix is obtained by interchanging its rows
                    into columns and columns into rows. For example,

                                                1     2    3
                     If size=3 and matrix a[][] is          4  5  6
                                                7     8    9


                                                1    4     7
                     then, its transpose b[][] will be     2  5  8
                                                3    6     9
                     Some of the members of the class are given below:
                     Class name                       :   Transpose
                     Data Members/Instance variables
                     s                                :   Integer to store size of the matrix
                     a[][]                            :   Integer two-dimensional matrix
                     b[][]                            :   Integer matrix to store the transpose of a[][]
                     Member Methods/Member functions
                     Transpose(int ss)                :   Initialises s to ss and declares the matrix
                     void input()                     :  Accepts numbers in matrix a[][]
                     void generate(int r, int c)      :     Using recursive technique, generates the transpose matrix in b[][]. Here parameters
                                                         ‘r’ and ‘c’ denote row and column position respectively
                     void print()                     :   Calls generate(int,int) and then prints the transpose matrix b[][]
                     Specify the class Transpose giving details of the constructor, void input(), int generate(int, int) and void print(). Define the main()
                    method to create an object and call the member functions accordingly to enable the task.














































             430 430  Touchpad Computer Science-XI
   427   428   429   430   431   432   433   434   435   436   437