TD5 finished.
This commit is contained in:
parent
0b57df1fe5
commit
784e1f6ff0
3 changed files with 63 additions and 2 deletions
13
td/td5/include/matrice.h
Normal file
13
td/td5/include/matrice.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "vector.h"
|
||||
|
||||
constexpr size_t MAX_MAT = 10;
|
||||
|
||||
class Matrice {
|
||||
public:
|
||||
Matrice();
|
||||
~Matrice();
|
||||
Vector<float>*& operator[](const int indice);
|
||||
friend std::ostream& operator<<(std::ostream& stream, const Matrice& mat);
|
||||
private:
|
||||
Vector<float>* _vectors[MAX_MAT];
|
||||
};
|
|
@ -1,8 +1,8 @@
|
|||
#include "../include/vector.h"
|
||||
#include "../include/smart_vector.h"
|
||||
#include "../include/deque.h"
|
||||
// Joker : slice.h
|
||||
// Joker : vector_iteraor.h
|
||||
#include "../include/matrice.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main(void)
|
||||
|
@ -10,5 +10,22 @@ int main(void)
|
|||
Vector<float> floatVect(4,3.5f);
|
||||
std::cout << floatVect * 9.0f << std::endl;
|
||||
std::cout << 9.0f * floatVect << std::endl;
|
||||
|
||||
Matrice mat;
|
||||
|
||||
mat[0] = new Vector<float>(6,30.0f);
|
||||
//mat[1] = &floatVect;
|
||||
// This leads to pointer error when calling the ~Matrice() func.
|
||||
mat[2] = new Smart_Vector<float>(7, 20.0f);
|
||||
|
||||
/*
|
||||
auto multipleVect = new Vector<float>[2];
|
||||
for(size_t i = 0; i< 2 ; i++)
|
||||
multipleVect[i].PushBack(1.9);
|
||||
mat[3] = multipleVect;
|
||||
*/
|
||||
// This leads to an error because each Vector should not be an array but only a pointer.
|
||||
|
||||
std::cout << mat << std::endl;
|
||||
return 0;
|
||||
}
|
31
td/td5/src/matrice.cpp
Normal file
31
td/td5/src/matrice.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include "../include/matrice.h"
|
||||
#include <iostream>
|
||||
|
||||
Matrice::Matrice()
|
||||
{
|
||||
for(size_t i=0; i<MAX_MAT; i++)
|
||||
_vectors[i] = NULL;
|
||||
}
|
||||
|
||||
Matrice::~Matrice()
|
||||
{
|
||||
for(size_t i=0; i<MAX_MAT; i++)
|
||||
delete _vectors[i];
|
||||
}
|
||||
|
||||
Vector<float>*& Matrice::operator[](const int indice)
|
||||
{
|
||||
if((indice > 10) || (indice < 0))
|
||||
throw "A Matrix is composed of 10 arrays of vectors.";
|
||||
return _vectors[indice];
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream,const Matrice& mat)
|
||||
{
|
||||
for(size_t i=0; i<MAX_MAT; i++)
|
||||
{
|
||||
if(mat._vectors[i] != NULL)
|
||||
stream << "Mat[" << i << "]: {" << *(mat._vectors[i]) << "}\t";
|
||||
}
|
||||
return stream;
|
||||
}
|
Loading…
Add table
Reference in a new issue