diff --git a/tp1/main.cpp b/tp1/main.cpp new file mode 100755 index 0000000..f791fb5 --- /dev/null +++ b/tp1/main.cpp @@ -0,0 +1,44 @@ +#include +#include "pile.h" + +int main() +{ + int tableauJeton[2]={10,12}; + t_pile pileA; + std :: cout << "pileA.initialiser();" << std :: endl; + std :: cout << "Sommet :" << pileA.sommet() << std :: endl; + std :: cout << "Dernier Jeton :" << pileA.dernier_jeton() << std :: endl << std :: endl; + pileA.empiler(10); + std :: cout << "pileA.empiler(10);" << std :: endl; + std :: cout << "Sommet :" << pileA.sommet() << std :: endl; + std :: cout << "Dernier Jeton :" << pileA.dernier_jeton() << std :: endl << std :: endl; + pileA.empiler(15); + std :: cout << "pileA.empiler(15);" << std :: endl; + std :: cout << "Sommet :" << pileA.sommet() << std :: endl; + std :: cout << "Dernier Jeton :" << pileA.dernier_jeton() << std :: endl << std :: endl; + pileA.empiler(20); + std :: cout << "pileA.empiler(20);" << std :: endl; + std :: cout << "Sommet :" << pileA.sommet() << std :: endl; + std :: cout << "Dernier Jeton :" << pileA.dernier_jeton() << std :: endl << std :: endl; + pileA.depiler(); + std :: cout << "pileA.depiler();" << std :: endl; + std :: cout << "Sommet :" << pileA.sommet() << std :: endl; + std :: cout << "Dernier Jeton :" << pileA.dernier_jeton() << std :: endl << std :: endl; + t_pile pileB(2,tableauJeton); + std :: cout << std :: endl << "t_pile pileB(2,tableauJeton);" << std :: endl; + std :: cout << "Sommet :" << pileB.sommet() << std :: endl; + std :: cout << "Dernier Jeton :" << pileB.dernier_jeton() << std :: endl << std :: endl; + pileB.empiler(30); + std :: cout << "pileB.empiler(30);" << std :: endl; + std :: cout << "Sommet :" << pileB.sommet() << std :: endl; + std :: cout << "Dernier Jeton :" << pileB.dernier_jeton() << std :: endl << std :: endl; + pileB.depiler(); + std :: cout << "pileB.depiler();" << std :: endl; + std :: cout << "Sommet :" << pileB.sommet() << std :: endl; + std :: cout << "Dernier Jeton :" << pileB.dernier_jeton() << std :: endl << std :: endl; + pileB.depiler(); + std :: cout << "pileB.depiler();" << std :: endl; + std :: cout << "Sommet :" << pileB.sommet() << std :: endl; + std :: cout << "Dernier Jeton :" << pileB.dernier_jeton() << std :: endl << std :: endl; + return 0; +} diff --git a/tp1/pile.cpp b/tp1/pile.cpp new file mode 100755 index 0000000..cbb11e3 --- /dev/null +++ b/tp1/pile.cpp @@ -0,0 +1,55 @@ +#include +#include "pile.h" + +t_pile :: t_pile(void) +{ + m_imax = -1; +}; + +t_pile :: t_pile(int customImax, int customJeton[]) +{ + m_imax = -1; + if(customImax < -1) + { + std :: cout << std :: endl << "t_pile : Erreur, imax inferieur a -1" << std :: endl; + } + else + { + while(m_imax=10) + { + std :: cout << std :: endl << "t_pile : Erreur, valeur de jeton max depassee" << std :: endl; + } + else + { + m_imax ++; + m_jeton[m_imax]=newJeton; + }; +}; + +void t_pile :: depiler(void) +{ + m_jeton[m_imax]=0; + m_imax--; +}; + +int t_pile :: sommet(void) +{ + return m_imax; +}; + +int t_pile :: dernier_jeton(void) +{ + return m_jeton[m_imax]; +}; + +t_pile :: ~t_pile(void){}; diff --git a/tp1/pile.h b/tp1/pile.h new file mode 100755 index 0000000..1a1097e --- /dev/null +++ b/tp1/pile.h @@ -0,0 +1,22 @@ +#ifndef PILE_H_INCLUDED +#define PILE_H_INCLUDED +class t_pile +{ +private : + + int m_jeton[10]; + int m_imax; + +public : + t_pile(void); + t_pile(int customImax, int customJeton[]); + void initialiser(void); + void empiler(int newJeton); + void depiler(void); + int sommet(void); + int dernier_jeton(void); + ~t_pile(void); +}; +#endif // PILE_H_INCLUDED + + diff --git a/tp1/tp1.cbp b/tp1/tp1.cbp new file mode 100755 index 0000000..6279c90 --- /dev/null +++ b/tp1/tp1.cbp @@ -0,0 +1,43 @@ + + + + + +