Matrix Multiplcation using classes

Hello all!
So I have an assignment to create a matrix multiplication program using classes (no friend functions). To be quite frank, I am completely lost and have no idea what I'm doing here.
The directions state that the private class hold 3 matricies and also that I need to have three member functions : one to initiate any program arrays, one that inputs the data, and one that calculates the matrix multiplication. Any input would be greatly appreciated!

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
using namespace std;

class Matrix
{
	int a[3][3];
	int b[3][3];
	int c[3][3];
	int i,j,k;
public:
	void Mult();
	void InputMatrix();
	void OutputMatrix();
};

void Matrix::InputMatrix()
{
	cout << "Enter the values for the first matrix";
	cout << "\n Matrix 1, Row 1:";
	for (i=0; i<3; i++)
	{
		for (j=0; j<3; j++)
		{
			cin >> a[i][j];
		}
	}
	cout << "Enter the values for the second matrix";
	for (i=0; i<3; i++)
	{
		for (j=0; j<3; j++)
		{
			cin >> b[i][j];
		}
	}
}

void Matrix::Mult()
{
	for (i=0; i<3; i++)
	{
		for (j=0; j<3; j++)
		{
			c[i][j]=0;
			for (k=0; k<3; k++)
			{
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}
}

void Matrix::OutputMatrix()
{
	cout << "The Resultant Matrix is: \n";
	for (i=0; i<3; i++)
	{
		for (j=0; j<3; j++)
		{
			cout << c[i][j];
		}
		cout << endl;
	}
}

int main()
{
	Matrix x;
	x.InputMatrix();
	x.Mult();
	x.OutputMatrix();
	system ("pause");
	return 0;
}

edit : this is just the rough draft of what I have to do with much more editing to follow the details of the instructions
Last edited on
I would also have to make the program input the matricies row by row as well as ask for a repeat..
Any help would be appreciated as I am thoroughly confused with c++
Last edited on
Topic archived. No new replies allowed.