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!
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++

#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;
}

OK, this is a very peculiar way to do this, but if that's the assignment, there's nothing to be done for it.

I take that back. It's a ridiculous way to do it. Are you certain that you're supposed to have three different matrices in a single object? Normally, I would assume that what is desired is to have each object represent a single matrix, with the multiplication method taking a Matrix as an argument. doing it this way is absurdly limiting, and simply bad design.

If I were in a course where a professor handed out this assignment, I would walk out, because the instructor obviously doesn't know how to write object-oriented programs.

I suspect, however, that there's a simple miscommunication involved. I don't normally ask this, but could you post the exact assignment for us?

The prompt asks me to have the user enter each row of the matrix one by one. I am not sure how to do this...Also, the prompt states
At minimum, the program will:
Use a class to hold 3 matricies of type private and use member function, only use non-inline functions and no friend functions allowed.
Have a member function called mult that will perform the actal matrix multiplication
Have a member function that inputs the data into the two input arrays from the keyboard using screen prompt above
Have a member function or functions that initialize any program arrays
The program will ask the user if he/she wishes to run the program again.

Well, the good news is, you seem to have most of it done. Aside from the input issue, what did you need help with?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.