Question: I'm trying to write a matrix class in c++ that can calculate the determinant . Please help me correct four compiler errors that I'm getting

I'm trying to write a matrix class in c++ that can calculate the determinant . Please help me correct four compiler errors that I'm getting in Visual Studio 2015.

C2059 - incorrect use of *

C2143

C2988

here is my header file

#pragma once

#ifndef MATRIX_H

#define MATRIX_H

#include

using namespace std;

template

class matrix

{

public:

int getRow();

int getCol();

t** getMatrix2D();

//t determinantOfMatrix(); //This is just a getter function.

matrix();

matrix(t** mtrx);

t determinant;

//~matrix();

bool operator==(const t & mtrx) const;

bool operator!=(const t & mtrx) const;

//bool operator<(const t & mtrx) const;

//bool operator>(const t & mtrx) const;

//bool operator<=(const t & mtrx) const;

//bool operator>=(const t & mtrx) const;

//matrix operator+(const t & mtrx);

//matrix operator-(const t & mtrx);

//matrix operator*(const t & mtrx);

private:

void getCof(t** mtrx);

t calculateDeterminant(t** mtrx);

//void checkROWSandCOLUMNS();

int row = ROWS, col = COLUMNS;

t** matrixArray2D = new t[row][col];

t* cofactors;

t* matrixArray = new t[row * col];

};

#endif // !MATRIX_H

Here is the CPP file:

#include"matrix.h"

using namespace std;

template

int matrix::getRow()

{

return row;

}

template

int matrix::getCol()

{

return col;

}

template

t ** matrix::getMatrix2D()

{

return matrixArray2D;

}

//template

//t matrix::determinantOfMatrix()

//{

// return determinant;

//}

template

matrix::matrix()

{

}

template

matrix::matrix(t** mtrx)

{

//checkROWSandCOLUMNS();

//int width = sizeof(mtrx*[0]) / sizeof(mtrx[0][0]); // number of columns(x);

//int height = sizeof(mtrx**) / sizeof(mtrx*[0]); // number of rows(y)

for (int i = 0; i < row; i++) {

for (int j = 0; j < col; j++) {

matrixArray2D[i][j] = mtrx[i][j]; //input array 2d to member array 2d

matrixArray[i*col + j] = mtrx[i][j]; // input array 2d to member array 1d

}

}

determinant = calculateDeterminant(mtrx)

}

template

bool matrix::operator==(const t & mtrx) const

{

for (int i = 0; i < row; i++)

for (int j = 0; j < col; j++)

if (mtrx[i][j] != mtrx[i][j]) return false;

return true;

}

template

bool matrix::operator!=(const t & mtrx) const

{

for (int i = 0; i < row; i++)

for (int j = 0; j < col; j++)

if (mtrx[i][j] == mtrx[i][j]) return false;

return true;

}

template

t matrix::calculateDeterminant(t** mtrx) {

if (row != col) return -1;

else if (ROWS == 2 && COLUMNS == 2) {

return mtrx[0][0] * mtrx[1][1] - mtrx[0][1] * mtrx[1][0];

}

else {

getCof(mtrx);

t** tempMatrix = new t[row - 1][col - 1];

for (int i = 0; i < row - 1; i++) {

for (int j = 0; j < col - 1; j++) {

tempMatrix[i][j] = mtrx[i + 1][j + 1];

}

}

t sum = 0;

matrix temp(tempMatrix);

for (int i = 0; i < col; i++) {

sum += cofactors[i] * calculateDeterminant(temp.getMatrix2D());

}

return sum;

}

}

//template

//void matrix::checkROWSandCOLUMNS()

//{

//}

template

void matrix::getCof(t** mtrx)

{

t* cofactorrArray = new t[col];

for (int j = 0; j < col; j++) {

cofactorrArray[j] = mtrx[0][j] ? j % 2 == 0 : mtrx[0][j] * -1;

}

cofactors = cofactorrArray;

}

Thanks in advance.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!