TP1: pile

This commit is contained in:
Yohan Boujon 2021-12-18 14:57:21 +01:00
parent 9d6885a3b9
commit 9aa259a40c
4 changed files with 164 additions and 0 deletions

44
tp1/main.cpp Executable file
View file

@ -0,0 +1,44 @@
#include <iostream>
#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;
}

55
tp1/pile.cpp Executable file
View file

@ -0,0 +1,55 @@
#include <iostream>
#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<customImax-1)
{
m_imax++;
m_jeton[m_imax]=customJeton[m_imax];
};
};
};
void t_pile :: empiler(int newJeton)
{
if (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){};

22
tp1/pile.h Executable file
View file

@ -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

43
tp1/tp1.cbp Executable file
View file

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="tp1" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/tp1" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/tp1" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="main.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>