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...)

Header
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef MATRIX_H
#define MATRIX_H
using namespace std;
class matrix{
private:
	int row, column;		//number of rows and columns used
	double array[MAX_ROWS][MAX_COLUMNS];
public:
	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)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<iostream>
#include"matrix.h"
using namespace std;

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

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

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

	return*this;
}

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;
		for(k=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;
		}
	}
	else
		cout << "Error";
	
	return a;
}


Source File (Main)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include"matrix.h"
#include<iostream>
using namespace std;
int main(){
	double a[MAX_ROWS, MAX_COLUMNS];
	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!!!!
(:
Topic archived. No new replies allowed.