I have the following exercise in which they ask me to compare a value with the numbers of a matrix given a precision that can not be exceeded, the numbers that meet that condition will be printed in a new matrix and if they do not comply, it will be printed a 0.
I have tried to do it, this is the function that they give me in the header file: previously, I declared a global variable with precision
const double epsilon=1e-3;
void filtra(matrix_t& M, matrix_item_t it, double precision);
Well, in the hpp the development, and I've put this:
void matrix_t::filtra(const matrix_t& M, matrix_item_t it, double epsilon) {
redimensiona(m_,n_); //destruí la matriz A y la redimensioné asignándole un número de filas y columnas
matrix_t E; //esta matriz la declará para que guarde los números de la matriz A que cumplan con la precisión,y los que no cumplan, que guarde un 0 en su posición en mi nueva matriz,al usar funciones booleanas
for (i=0; i<(E.get_m()); i++) {
for (j=0; j<(E.get_n());j++)
if ((E.get_matrix_item(i,j))-matrix_item_t it < epsilon){
E.set_matrix_item(i,j);
}
M
is a dynamic array that contains the rows and columns of the matrix A
, the original matrix matrix_item_t
it is the element that I have to search in the matrix A
.
Then in the main
, I put this:
matrix_t A;
matrix_t &B=matrix_t A;
matrix_t &E=matrix_t B;
cout << endl;
A.read(cin);
cout << "--- MATRIZ ORIGINAL ---" << endl;
B.write();
cout << "--- PRECISIÓN 0.001 ---" << endl;
A.filtra(B,5.254,1E-3);
cout << "--- PRECISIÓN 0.001 ---" << endl;
A.filtra(B,5.254,1E-3);
B.write();
B.write();
cout << "--- PRECISIÓN 0.01 ---" << endl;
B.write();
cout << "--- PRECISIÓN 0.1 ---" << endl;
A.filtra(B,5.254,1E-1);
B.write();
cout << "--- PRECISIÓN 1.0 ---" << endl;
A.filtra(B,5.254,1.0);
B.write();
This last part was given to me in the exercise as a code that I had to put in the main, A.filtra's ...
what I put is matrix_t &B=matrix_t A;
matrix_t &E=matrix_t B;
until it starts A.filtra
, and obviously everything about cpp and hpp I did, the problem is that when I compile I get a lot of errors, and it costs me To understand the errors pointed out by the compiler:
main_m_3.cpp: In function ‘int main()’:
main_m_3.cpp:25:18: error: redeclaration of ‘matrix_t A’
matrix_t A;
^
main_m_3.cpp:5:11: note: ‘matrix_t A’ previously declared here
matrix_t A;
^
main_m_3.cpp:26:18: error: conflicting declaration ‘matrix_t B’
matrix_t B;
^
main_m_3.cpp:12:18: note: previous declaration as ‘const matrix_t& B’
const matrix_t& B=A;
^
main_m_3.cpp:27:21: error: conversion from ‘const matrix_t*’ to non-scalar type ‘matrix_t’ requested
matrix_t E=&B;
^
main_m_3.cpp:35:3: error: ‘class matrix_t’ has no member named ‘filtra’
A.filtra(B,5.254,1E-4);
^
main_m_3.cpp:39:3: error: ‘class matrix_t’ has no member named ‘filtra’
A.filtra(B,5.254,1E-3);
^
main_m_3.cpp:43:3: error: ‘class matrix_t’ has no member named ‘filtra’
A.filtra(B,5.254,1E-2);
^
main_m_3.cpp:47:3: error: ‘class matrix_t’ has no member named ‘filtra’
A.filtra(B,5.254,1E-1);
^
main_m_3.cpp:51:3: error: ‘class matrix_t’ has no member named ‘filtra’
A.filtra(B,5.254,1.0);
^
no ‘void matrix_t::filtra(const matrix_t&, matrix_item_t, double)’ member function declared in class ‘matrix_t’
void matrix_t::filtra(const matrix_t& M, matrix_item_t it, double epsilon)
The truth is that I do not know where the code fails, a lot of help is appreciated
Thank you very much.