Matrix - Add, Subtract, Multiply

Hi everyone. I am trying to create a matrix. I'm trying to write a matrix program that the user will input the matrices and the program will add, subtract, and multiply the 2 matrices. My problem is I work 3 jobs and am taking 19 credit hours in college so I haven't had much time to read my book. I'm in my 2nd semester of C++. My book says:
before performing the required data manipulation, each function should validate its input arguments. The dimensions of the matrices involved in an operation must be compatible for that operation. Here is what I have:

(It's not completed. There are a LOT of things I put in not as code but as a reminder of what I need to do...)

#ifndef MATRIX_H
#define MATRIX_H
using namespace std;
class matrix{
int row, column; //number of rows and columns used
double array[MAX_ROWS][MAX_COLUMNS];
matrix(double[][MAX_COLUMNS], int, int);
matrix& operator += (matrix); // a+=b
matrix& operator *= (double); // a*=3
friend matrix operator+(matrix, matrix); //c=a+b
friend matrix operator*(double, matrix); //b=3*a
friend matrix operator*(matrix, matrix); //c=a*b
friend ostream& operator << (ostream&, const matrix&); //displays
#endif; //MATRIX_H

Implementation (Resource File)
using namespace std;

const int MAX_ROWS = 3;
const int MAX_COLUMNS = 3;

matrix& operator += (matrix){
int sum = 0;

if( = ){
sum = ;
cout << "Arrays not same size";


friend matrix operator * (matrix, matrix){ //multiply 2 matrices
a.columns = b.rows; //i, j element of the product

double productArray[MAX_ROWS][MAX_COLUMNS];

if(columns = rows){
productArray[i][j] = 0;
productArray[i][j] += a[i][k]*b[i][k];
productArray.rows = a.rows;
productArray.columns = b.columns;

matrix c(productArray, rows, columns);

return c;
cout << "Error";

return a;

Source File (Main)
using namespace std;
int main(){
for(int i=0; i<2; i++){
cout << "Enter three numbers: ";
for(int j=0; j<2; j++)
cin >> a[i][j];

matrix myMatrix (a,2,2);
myMatrix += myMatrix;
myMatrix b = myMatrix + 3 * matrix;
cout << b << endl;

return 0;

Any and all help will be appreciated!! (: I'm so confused on how to even create a matrix... Thank you!!!!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!