jeudi 24 décembre 2015

Matrix class C++

hey there i'm a student in computer science , we have got a terrible teacher that doesn't know ho to teach.. bad luck. we are asked to build a generic matrix using the vector class and we are not allowed to use "new" and "delete" at all. I don't know how to start it properly we can use these libraries:

cassert

vector

cstdlib

cmath

i searched all over the internet but didn't found a class that uses the vector as the matrix(index of matrix is mat[i*cols+j] and doesn't use new and delete function or allocate memory :

examples of what we are supposed to check:(int google test)

"Matrix.hpp"

"gtest/gtest.h"

Matrix<int> mat1(1, 1, std::vector<int>(1,2));

EXPECT_EQ(1, mat1.getRowNum());
EXPECT_EQ(1, mat1.getColNum());

int t= 0;
EXPECT_TRUE(mat1.hasTrace(t));
EXPECT_TRUE(mat1.isSquareMatrix());

Matrix<int> transpose_mat= mat1;
EXPECT_EQ(transpose_mat, mat1.transpose());

Matrix<int> mat2(1, 1, std::vector<int>(1,3));
Matrix<int> add_mat(1, 1, std::vector<int> (1,5));
EXPECT_EQ(add_mat, mat1+mat2);

Matrix<int> multi_mat(1, 1, std::vector<int>(1,6));
EXPECT_EQ(multi_mat, mat1*mat2);

Matrix<int> scalar_multi_mat(1, 1, std::vector<int>(1,4));
EXPECT_EQ(scalar_multi_mat, mat1*2);

} thanks

Aucun commentaire:

Enregistrer un commentaire