-
Notifications
You must be signed in to change notification settings - Fork 0
/
etat.cpp
63 lines (53 loc) · 1.04 KB
/
etat.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "etat.h"
#include <stdexcept>
unsigned int Etat::getDimension() const
{
return dimension;
}
bool Etat::getCellule(unsigned int n) const
{
if(n > dimension - 1)
throw std::out_of_range("Cellule hors du tableau");
return tab[n];
}
void Etat::setCellule(unsigned int i, bool val)
{
if(i > dimension - 1)
throw std::out_of_range("Cellule hors du tableau");
tab[i] = val;
}
Etat& Etat::operator=(const Etat &e)
{
dimension = e.dimension;
tab = new bool[dimension];
for(int i = 0; i < dimension; i++)
tab[i] = e.tab[i];
return *this;
}
Etat::Etat(const Etat &e)
{
this->dimension = e.dimension;
this->tab = new bool(dimension);
for(int i = 0; i < e.dimension; i++)
this->tab[i] = e.tab[i];
}
Etat::Etat(unsigned int dim=0) : dimension(dim)
{
tab = new bool(dimension);
for(int i = 0; i < dimension; i++)
tab[i] = false;
}
Etat::~Etat()
{
delete tab;
}
std::ostream &operator<<(std::ostream &flux, Etat e)
{
for(int i = 0; i < e.getDimension(); i++){
if(e.getCellule(i))
flux << "X";
else
flux << " ";
}
return flux;
}