Implement a class Matrix to create matrices of 2x2, 3x3 and 4x4 with the following private
datamembers:
1. int **matrix – a double pointer of type integer to create a 2D array (matrix)
2. int row – an integer to store the rows in the matrix
3. int col – an integer to store the columns in the matrix
The class shall have the following public member functions:
1. Matrix Add(Matrix m) – adds the calling object matrix with the one passed as an argument and returns a resultant matrix
2. Matrix Subtract(Matrix m) – subtracts the calling object matrix with the one passed as an argument and returns a resultant matrix
3. Matrix Multiply(Matrix m) – multiplies the calling object matrix with the one passed as an argument and returns a resultant matrix
4. int FindkSmallest(int k) – a function that finds the kth smallest element in the matrix. If k is 1, return the smallest element. If k is 2 return the second smallest element and so on.
5. Matrix merge(Matrix m) - a function to merge two matrices.
Comments
Leave a comment