13102 - Matrix Not the Matrix   

Description

Complete an existed class Matrix, which is used to store and calculate matrix (mathe-matics).

 

Matrix

Private Variables:

  • row(int) represents as the size of rows in a matrix.
  • col(int) represents as the size of columns in a matrix.
  • val(vector<int>) use to store a mtrix’s elements.

Constructors:

  • Matrix(int r, int c) – Should initalize the size of rows (row) and columns (col)  to r and c.

Public Methods:

  • Matrix operator+(const Matrix &other) – Should return a matrix which is the addition of the two input matrices.
  • Matrix operator-(const Matrix &other) – Should return a matrix which is the subtraction of the two input matrices.

note: only when two matrices have the same size on both rows and columns can be added or subtracted.

If the conditions are not met, return a Matrix(0, 0) and print “Uncalculable

  • Matrix operator*(const Matrix &other) – Should return a matrix which is the multiplication of the two input matrices.

note: only when the size of columns in the first matrix equals to the size of rows in the second matrix can those two matrices be multiplied.

If the conditions are not met, return a Matrix(0, 0) and print “Uncalculable

  • friend ostream &operator<<(ostream &os, const Vector2 &v) – For print out a Matrix variable.

Must follow below format:

[ a b c

  d e f ]

note: above show a Matrix(2, 3), there is always have “[ in front of the first element, and “ ]followed by the last element. Also, need two spaces “  “ in front of the first element in each row(except row[0])

  • void readInput()stdin elements and put them into the val vector. (no need implement)
 

Input

No need to handle input.

Four kinds of input command would be given. Check main.cpp for more details.

 

Output

No need to handle output. Check main.cpp for more details.

Sample Input  Download

Sample Output  Download

Partial Judge Code

13102.cpp

Partial Judge Header

13102.h

Tags




Discuss