Question
I need some help with the two other classes i have been working on. The test class does not to be modified but matrix3d.hpp and
I need some help with the two other classes i have been working on. The test class does not to be modified but matrix3d.hpp and .cpp do. Right now I'm just trying to get the matrix to work, and I would love to know what I did wrong and how to correct them
here is test-3-matrix3d.cpp
#include "catch/catch.hpp"
#include "../matrix3d.hpp"
TEST_CASE ("Default Matrix")
{
Matrix3D m;
CHECK(0 == m.GetValue(0, 0));
}
TEST_CASE ("Specified Matrix")
{
/*
1 0 2
1 2 0
1 0 0
*/
Matrix3D m(1,0,2, 1,2,0, 1,0,0);
CHECK(1 == m.GetValue(0, 0));
CHECK(2 == m.GetValue(0, 2));
}
TEST_CASE ("Determinant for default matrix")
{
Matrix3D m;
CHECK(0 == m.Determinant());
}
TEST_CASE ("Determinant for specified matrix")
{
Matrix3D m(1,0,2, 1,2,0, 1,0,0);
CHECK(-4 == m.Determinant());
}
matrix3d.hpp
#ifndef MATRIX3D_HPP
#define MATRIX3D_HPP
class Matrix3D
{
private:
const static int r =3;
const static int c =3;
int i =0;
int j =0;
public:
Matrix3D(int arr[r][c]);
int GetValue(int arr[r][c]);
int Determinant();
};
#endif
matrix3d.cpp
#include "matrix3d.hpp"
Matrix3D::Matrix3D(int arr[r][c])
{
for(int i=0; i< r;i++)
{
for(int j=0; j< c; j++)
{
arr[r][c] = arr[i][j];
}
}
}
int Matrix3D::GetValue(int arr[r][c])
{
this-> i =i;
this-> j=j;
return this-> arr[i][j];
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started