Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Made some modification in your code. Please find fixed code below -</p> <pre><code>#include &lt;iostream&gt; #include &lt;iomanip&gt; using namespace std; // Base class IMatriz; class IMatriz { int **m; int numRows; int numColumns; public: IMatriz(){ numRows = 0; numColumns = 0; m = NULL; } IMatriz(int r, int c) { numRows = r; numColumns = c; m = new int* [numRows]; for(int i=0; i &lt; numRows; i++) m[i] = new int [numColumns]; } virtual void setSize(int r, int c) = 0; virtual void setValue(int row, int col, int val) = 0; virtual int getValue(int row, int col) = 0; virtual int getNumRows() = 0; virtual int getNumColumns() = 0; virtual void mult(IMatriz &amp;a, IMatriz &amp;b) = 0; virtual void print(void) = 0; }; // Inherited class Matriz : public IMatriz { protected: int **m; int numRows; int numColumns; public: Matriz() : IMatriz() { } Matriz(int r, int c) : IMatriz(r, c) { numRows = r; numColumns = c; m = new int* [numRows]; for(int i=0; i &lt; numRows; i++) m[i] = new int [numColumns]; } void setSize(int r, int c); void setValue(int row, int col, int val); int getValue(int row, int col); int getNumRows(); int getNumColumns(); void mult(IMatriz &amp;a, IMatriz &amp;b); void print(); }; // Functions void Matriz::setSize(int r, int c) { numRows = r; numColumns = c; } void Matriz::setValue(int row, int col, int val) { m[row][col] = val; } int Matriz::getValue(int row, int col) { return m[row][col]; } int Matriz::getNumRows() { return numRows; } int Matriz::getNumColumns() { return numColumns; } void Matriz::mult(IMatriz &amp;a, IMatriz &amp;b) { // m.setSize( a.getNumRows(), b.getNumColumns() ); // for (int rows = 0; rows &lt; numRows; rows ++) // for (int cols = 0; cols &lt; numColumns; cols ++) // m[rows][cols] = 0; // for (int rows = 0; rows &lt; a.getNumRows(); rows ++) // for (int cols = 0; cols &lt; b.getNumColumns(); cols ++) // for (int auxl = 0; auxl &lt; a.getNumColumns(); auxl ++) // m[rows][cols] += (a[rows][auxl] * b[auxl][cols]); return; } void Matriz::print() { for (int rows = 0; rows &lt; numRows; rows ++) { for (int cols = 0; cols &lt; numColumns; cols ++) cout &lt;&lt; m[rows][cols] &lt;&lt; " "; cout &lt;&lt; endl; } } // Principal int main(int argc, const char * argv[]) { Matriz m; Matriz a(3, 2); Matriz b(2, 3); a.setValue(0,0,7); a.setValue(0, 0, 7); a.setValue(1, 0, 1); a.setValue(2, 0, 8); a.setValue(0, 1, 2); a.setValue(1, 1, 5); a.setValue(2, 1, 6); b.setValue(0, 0, 2); b.setValue(1, 0, 3); b.setValue(0, 1, 5); b.setValue(1, 1, 4); b.setValue(0, 2, 8); b.setValue(1, 2, 9); a.print(); b.print(); // m.mult(a,b); // m.print(); return 0; } </code></pre> <p>This is the output i get on xcode console - </p> <pre><code>7 2 1 5 8 6 2 5 8 3 4 9 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload