I keep getting a no throw exception for the code I am writing for matrix multiplication. The error is happening in my display function where my cout statement is Im not sure if it is my syntax or if Im setting something to null in the array without knowing. Any help would be appreciated.
#include<iostream>
using namespace std;
const int ROWS = 3;
const int COLUMNS = 3;
class Matrix
{
int p[ROWS][COLUMNS];
int row, column;
public:
void InputMatrix();
void display();
friend Matrix operator*(Matrix matrix1, Matrix matrix2);
};
Matrix operator*(Matrix matrix1, Matrix matrix2)
{
Matrix temp;
for (int i = 0; i < ROWS; i++)
{
for (int j = 0; j < COLUMNS; j++)
{
temp.p[i][j] = 0;
for (int k = 0; k < ROWS; k++)
{
temp.p[i][j] = temp.p[i][j] + (temp.p[i][k] * temp.p[k][j]);
}
}
}
return temp;
}
void Matrix::InputMatrix()
{
for (int i = 0; i < ROWS; i++)
{
for (int j = 0; j < COLUMNS; j++)
{
cout << "Enter elements of row " << i + 1 << " and column "
<< j + 1 << endl;
cin >> p[i][j];
}
}
}
void Matrix::display()
{
for (int i = 0; i < ROWS; i++)
{
for (int j = 0; j < COLUMNS; i++)
{
cout << " " << p[i][j];
}
cout << endl;
}
}
int main()
{
Matrix matrix1;
Matrix matrix2;
Matrix matrix3;
cout << "Enter elements for the first matrix: " << endl;
matrix1.InputMatrix();
system("cls");
cout << "Enter elements for the second matrix: " << endl;
matrix2.InputMatrix();
matrix3 = matrix1 * matrix2;
matrix3.display();