Saturday 20 February 2016

Matrix ADT

You have to implement a matrix ADT using concepts of C++ classes taught in the lectures. The input matrices would be square matrices. The  class must support the following functions:
1. Matrix Addition
2. Matrix Subtraction
3. Matrix Multiplication
The program should take as input: dimension of a square matrix N, two matrices of size N x N with integer values, and one operator symbol (+, - ,*). It must perform the corresponding operation using member functions of Matrix class. You are supposed to implement the following functions of the class MatrixADT matrixType add(matrixType M1, matrixType M2): The function should add matrices M1 and M2 and store the result in "resultMatrix". The function should return the "resultMatrix".
matrixType subtract(matrixType M1, matrixType M2):
The function should subtract matrix M2 from M1 and store the result in "resultMatrix". The function should return the "resultMatrix".
matrixType multiply(matrixType M1, matrixType M2):
The function should multiply matrices M1 and M2 and store the result in "resultMatrix". Be careful, it is M1*M2 and not M2*M1. The function should return the "resultMatrix".

INPUT:
In the first line, one integer which is the dimension of the matrix  and one operator (one of +, - or *)
Two NxN matrices one after the other, supplied one row at a time.
OUTPUT:
Resultant matrix after performing the specified operation, one row at a time. For subtraction, if A is the first matrix and B is the second matrix, perform A-B.


CONSTRAINTS:
The inputs will satisfy the following constraints:
1<=N<=10
There is no need to validate the value of N.
There are no constraints on the values of the entries of the matrices.

Solution-:


After the deadline is over although you can ask for logic

4 comments:

  1. plz give some hints..not getting logic please help

    ReplyDelete
    Replies
    1. either you can overload the operators .
      but you can do one more thing.check the operator with their ascii value and accordingly sent the function call.

      Delete
  2. plz provide the code....I m not getting this

    ReplyDelete
  3. there is runtime error.. can anyone tell how can i return the resultant matrix?.. thanks

    ReplyDelete