From 9fe033ea88c2f705ec18c232873d056e0c229d72 Mon Sep 17 00:00:00 2001 From: Gaspard Coulet Date: Wed, 28 Apr 2021 23:05:53 +0200 Subject: Initial commit --- sem_3/Programm/TP1/test | Bin 0 -> 9240 bytes sem_3/Programm/TP1/test.cpp | 10 ++ sem_3/Programm/TP2/ex1/exo | Bin 0 -> 14053 bytes sem_3/Programm/TP2/ex1/itv.cpp | 71 ++++++++ sem_3/Programm/TP2/ex1/itv.h | 20 +++ sem_3/Programm/TP2/ex1/jeudelaviemine/cell.cpp | 43 +++++ sem_3/Programm/TP2/ex1/jeudelaviemine/cell.h | 24 +++ sem_3/Programm/TP2/ex1/jeudelaviemine/main | Bin 0 -> 13975 bytes sem_3/Programm/TP2/ex1/jeudelaviemine/main.cpp | 25 +++ sem_3/Programm/TP2/ex1/main.cpp | 12 ++ sem_3/Programm/TP2/ex1/makefile | 4 + sem_3/Programm/TP2/exo10/exo10.c | 19 +++ sem_3/Programm/TP2/exo10/main | Bin 0 -> 8551 bytes sem_3/Programm/TP2/exo11/exo11.c | 23 +++ sem_3/Programm/TP2/exo11/main | Bin 0 -> 8651 bytes sem_3/Programm/TP2/exo13/exo13.c | 0 sem_3/Programm/TP2/exo13/impair.c | 5 + sem_3/Programm/TP2/exo13/impair.h | 1 + sem_3/Programm/TP2/exo13/pair.c | 4 + sem_3/Programm/TP2/exo13/pair.h | 1 + sem_3/Programm/TP2/exo13/spair | Bin 0 -> 8695 bytes sem_3/Programm/TP2/exo13/spair.c | 11 ++ sem_3/Programm/cours-hlin302.pdf | Bin 0 -> 1960924 bytes sem_3/Programm/jeu_de_la_vie/JDV0-bis-main.cpp | 14 ++ sem_3/Programm/jeu_de_la_vie/JDV0-bis.cpp | 149 +++++++++++++++++ sem_3/Programm/jeu_de_la_vie/JDV0-bis.h | 38 +++++ sem_3/Programm/jeu_de_la_vie/arch/population.cpp | 145 ++++++++++++++++ sem_3/Programm/jeu_de_la_vie/arch/population.h | 53 ++++++ .../jeu_de_la_vie/arch/population_vivante.cpp | 42 +++++ .../jeu_de_la_vie/arch/population_vivante.h | 18 ++ sem_3/Programm/jeu_de_la_vie/cellule.cpp | 95 +++++++++++ sem_3/Programm/jeu_de_la_vie/cellule.h | 55 ++++++ sem_3/Programm/jeu_de_la_vie/option.cpp | 45 +++++ sem_3/Programm/jeu_de_la_vie/option.h | 47 ++++++ .../jeu_de_la_vie/population-vivante-v2.cpp | 184 +++++++++++++++++++++ .../Programm/jeu_de_la_vie/population-vivante-v2.h | 60 +++++++ sem_3/Programm/jeu_de_la_vie/tabOptions.cpp | 58 +++++++ sem_3/Programm/jeu_de_la_vie/tabOptions.h | 22 +++ 38 files changed, 1298 insertions(+) create mode 100644 sem_3/Programm/TP1/test create mode 100644 sem_3/Programm/TP1/test.cpp create mode 100644 sem_3/Programm/TP2/ex1/exo create mode 100644 sem_3/Programm/TP2/ex1/itv.cpp create mode 100644 sem_3/Programm/TP2/ex1/itv.h create mode 100644 sem_3/Programm/TP2/ex1/jeudelaviemine/cell.cpp create mode 100644 sem_3/Programm/TP2/ex1/jeudelaviemine/cell.h create mode 100644 sem_3/Programm/TP2/ex1/jeudelaviemine/main create mode 100644 sem_3/Programm/TP2/ex1/jeudelaviemine/main.cpp create mode 100644 sem_3/Programm/TP2/ex1/main.cpp create mode 100644 sem_3/Programm/TP2/ex1/makefile create mode 100644 sem_3/Programm/TP2/exo10/exo10.c create mode 100644 sem_3/Programm/TP2/exo10/main create mode 100644 sem_3/Programm/TP2/exo11/exo11.c create mode 100644 sem_3/Programm/TP2/exo11/main create mode 100644 sem_3/Programm/TP2/exo13/exo13.c create mode 100644 sem_3/Programm/TP2/exo13/impair.c create mode 100644 sem_3/Programm/TP2/exo13/impair.h create mode 100644 sem_3/Programm/TP2/exo13/pair.c create mode 100644 sem_3/Programm/TP2/exo13/pair.h create mode 100644 sem_3/Programm/TP2/exo13/spair create mode 100644 sem_3/Programm/TP2/exo13/spair.c create mode 100644 sem_3/Programm/cours-hlin302.pdf create mode 100644 sem_3/Programm/jeu_de_la_vie/JDV0-bis-main.cpp create mode 100644 sem_3/Programm/jeu_de_la_vie/JDV0-bis.cpp create mode 100644 sem_3/Programm/jeu_de_la_vie/JDV0-bis.h create mode 100644 sem_3/Programm/jeu_de_la_vie/arch/population.cpp create mode 100644 sem_3/Programm/jeu_de_la_vie/arch/population.h create mode 100644 sem_3/Programm/jeu_de_la_vie/arch/population_vivante.cpp create mode 100644 sem_3/Programm/jeu_de_la_vie/arch/population_vivante.h create mode 100644 sem_3/Programm/jeu_de_la_vie/cellule.cpp create mode 100644 sem_3/Programm/jeu_de_la_vie/cellule.h create mode 100644 sem_3/Programm/jeu_de_la_vie/option.cpp create mode 100644 sem_3/Programm/jeu_de_la_vie/option.h create mode 100644 sem_3/Programm/jeu_de_la_vie/population-vivante-v2.cpp create mode 100644 sem_3/Programm/jeu_de_la_vie/population-vivante-v2.h create mode 100644 sem_3/Programm/jeu_de_la_vie/tabOptions.cpp create mode 100644 sem_3/Programm/jeu_de_la_vie/tabOptions.h (limited to 'sem_3/Programm') diff --git a/sem_3/Programm/TP1/test b/sem_3/Programm/TP1/test new file mode 100644 index 0000000..8577d4f Binary files /dev/null and b/sem_3/Programm/TP1/test differ diff --git a/sem_3/Programm/TP1/test.cpp b/sem_3/Programm/TP1/test.cpp new file mode 100644 index 0000000..91757d7 --- /dev/null +++ b/sem_3/Programm/TP1/test.cpp @@ -0,0 +1,10 @@ +#include + +int Puissance ( int x, int n) {return n==0 ? 1 : x*Puissance(x,n-1);} + +int main () { +int a,b; +std::cin >> a >> b; +std::cout << Puissance( a,b) << std::endl; +return 0; +} diff --git a/sem_3/Programm/TP2/ex1/exo b/sem_3/Programm/TP2/ex1/exo new file mode 100644 index 0000000..3c36d84 Binary files /dev/null and b/sem_3/Programm/TP2/ex1/exo differ diff --git a/sem_3/Programm/TP2/ex1/itv.cpp b/sem_3/Programm/TP2/ex1/itv.cpp new file mode 100644 index 0000000..844d859 --- /dev/null +++ b/sem_3/Programm/TP2/ex1/itv.cpp @@ -0,0 +1,71 @@ +#include +#include"itv.h" + +float Itv::lenght () { + return bornesup-borneinf; +} + +void Itv::afficher () { + std::cout<<"["<=borneinf; +} +Itv::Itv () { + borneinf =0; + bornesup = 0; +} +Itv::Itv(float a, float b) { + bornesup = b; + borneinf = a; +} +void Itv::modifborne (int i, float f) { + if (i == 0 ) { + borneinf = f; + } + else if ( i == 1) { + bornesup = f; + } + else { + std::cout<< "Borne invalide, le premier param doit valoir 0 ( pour borne inf) ou 1 ( pour borne sup)" << std::endl; + } +} + +float Itv::getborne (int i) { + if (i == 0 ) { + return borneinf; + } + else if ( i == 1) { + return bornesup; + } + else { + std::cout<< "Borne invalide, le premier param doit valoir 0 ( pour borne inf) ou 1 ( pour borne sup)" << std::endl; + return 42; + } +} + +bool Itv::estegal ( Itv inter) { + return getborne(0)==inter.getborne(0) && getborne(1) == inter.getborne(1); +} + +bool Itv::estinclusstr ( Itv inter ) { + return getborne(0) > inter.getborne(0) && getborne(1) < inter.getborne(1); +} + +bool Itv::disjoint ( Itv inter) { + return getborne(1) < inter.getborne(0) || getborne(0) > inter.getborne(1); +} + +bool Itv::accole ( Itv inter) { + return getborne(0) == inter.getborne(0) || getborne(0) == inter.getborne(1) || getborne(1) == inter.getborne(0)|| getborne(1) == inter.getborne(1); +} + +bool Itv::imbrique ( Itv inter) { + return !accole(inter) && !disjoint(inter) && !estinclusstr(inter) && !estegal(inter); +} + +void Itv::translat ( float f) { + borneinf += f; + bornesup += f; +} diff --git a/sem_3/Programm/TP2/ex1/itv.h b/sem_3/Programm/TP2/ex1/itv.h new file mode 100644 index 0000000..e8835cd --- /dev/null +++ b/sem_3/Programm/TP2/ex1/itv.h @@ -0,0 +1,20 @@ +class Itv { + private : + float borneinf, bornesup; + public : + Itv(); + Itv(float,float); + float lenght(); + void afficher(); + bool appartient(float); + void modifborne(int,float); + float getborne(int); + + bool estegal (Itv); + bool estinclusstr(Itv); + bool disjoint(Itv); + bool accole(Itv); + bool imbrique(Itv); + void translat(float); + +}; diff --git a/sem_3/Programm/TP2/ex1/jeudelaviemine/cell.cpp b/sem_3/Programm/TP2/ex1/jeudelaviemine/cell.cpp new file mode 100644 index 0000000..9c17eb7 --- /dev/null +++ b/sem_3/Programm/TP2/ex1/jeudelaviemine/cell.cpp @@ -0,0 +1,43 @@ +#include "cell.h" +#include + +void cell::setColor(color nouvelle){ + couleur = nouvelle; +} + +color cell::getColor(){ + return couleur; +} + +void cell::setVivante(bool a) { + statut = a; +} +int cell::getX () { + return x; +} + +int cell::getY () { + return y; +} +bool cell::getVivante() { + return statut; +} +void cell::printcell () { + std::cout << "La cellule ( à l'adresse mémoire " << this << " ) = {" << (statut ? "vivante" : "morte")<<", " << x << "x"< +#include"cell.h" + +bool cell_est_couleur(cell&, color); +void test_cell ( cell&); +int main ( int argc, char ** argv) { + cell cell1(1,2,true); + cell cell2(1,3,false); + std::cout<<"L'objet c1 est a l'adresse memoire" << &cell1<< std::endl; + std::cout<<"L'objet c2 est a l'adresse memoire" << &cell2<< std::endl; + test_cell(cell1); + test_cell(cell2); + std::cout<< (cell1.estvoisineenVie(cell2) ? "cell1 est voisine de cell2" : "cell1 n'est pas voisine de cell2")< +#include"itv.h" + +int main () { + Itv inter1; + Itv inter2(0,24.4); + inter1.afficher(); + inter2.afficher(); + inter2.translat(0.5); + inter2.afficher(); + return 0; +} diff --git a/sem_3/Programm/TP2/ex1/makefile b/sem_3/Programm/TP2/ex1/makefile new file mode 100644 index 0000000..fa907f2 --- /dev/null +++ b/sem_3/Programm/TP2/ex1/makefile @@ -0,0 +1,4 @@ +CC = g++ +FLAGS = -Wall +LIBS = + diff --git a/sem_3/Programm/TP2/exo10/exo10.c b/sem_3/Programm/TP2/exo10/exo10.c new file mode 100644 index 0000000..fc2f92e --- /dev/null +++ b/sem_3/Programm/TP2/exo10/exo10.c @@ -0,0 +1,19 @@ +#include +#include + +int puiss (int x, int y) { + return ( y == 0 ? 1 : x * ( puiss(x, y-1))); +} + +int main ( int argc, char ** argv) { + int lg = 0; int ret =0; + while (argv[1][lg]!=0) { + lg ++; + } + lg --; + for ( int i=lg; i >= 0; i --) { + ret += puiss(10,lg-i)*((int)(argv[1][i] )- 48); + } + printf("%d \n", ret); + return 0; +} diff --git a/sem_3/Programm/TP2/exo10/main b/sem_3/Programm/TP2/exo10/main new file mode 100644 index 0000000..a617d42 Binary files /dev/null and b/sem_3/Programm/TP2/exo10/main differ diff --git a/sem_3/Programm/TP2/exo11/exo11.c b/sem_3/Programm/TP2/exo11/exo11.c new file mode 100644 index 0000000..e0567c2 --- /dev/null +++ b/sem_3/Programm/TP2/exo11/exo11.c @@ -0,0 +1,23 @@ +#include +#include + +int puiss (int x, int y) { + return ( y == 0 ? 1 : x * ( puiss(x, y-1))); +} + +int main (int argc, char** argv) { + int ordre =1; int cp = atoi(argv[1]); int bc = cp; + while (cp / 10!= 0) { + ordre ++; + cp = cp /10; + } + printf("%d\n", ordre); + cp = bc; + char nbchar[ordre]; + for ( int i = 0; i < ordre; i ++) { + nbchar[i] = cp / puiss(10, ordre -i-1) + 48; + cp = cp % puiss(10,ordre-i -1); + } + printf("%s\n", nbchar); + return 0; +} diff --git a/sem_3/Programm/TP2/exo11/main b/sem_3/Programm/TP2/exo11/main new file mode 100644 index 0000000..3aeee19 Binary files /dev/null and b/sem_3/Programm/TP2/exo11/main differ diff --git a/sem_3/Programm/TP2/exo13/exo13.c b/sem_3/Programm/TP2/exo13/exo13.c new file mode 100644 index 0000000..e69de29 diff --git a/sem_3/Programm/TP2/exo13/impair.c b/sem_3/Programm/TP2/exo13/impair.c new file mode 100644 index 0000000..f61f5bc --- /dev/null +++ b/sem_3/Programm/TP2/exo13/impair.c @@ -0,0 +1,5 @@ +#include "pair.h" + +int impair ( unsigned int i) { + return (i == 0 ? 0 : ( pair(i-1))); +} diff --git a/sem_3/Programm/TP2/exo13/impair.h b/sem_3/Programm/TP2/exo13/impair.h new file mode 100644 index 0000000..196468b --- /dev/null +++ b/sem_3/Programm/TP2/exo13/impair.h @@ -0,0 +1 @@ +int impair(unsigned int); diff --git a/sem_3/Programm/TP2/exo13/pair.c b/sem_3/Programm/TP2/exo13/pair.c new file mode 100644 index 0000000..05b9a0a --- /dev/null +++ b/sem_3/Programm/TP2/exo13/pair.c @@ -0,0 +1,4 @@ +#include "impair.h" +int pair(unsigned int i){ + return (i == 0 ? 1 : impair(i-1)); +} diff --git a/sem_3/Programm/TP2/exo13/pair.h b/sem_3/Programm/TP2/exo13/pair.h new file mode 100644 index 0000000..2b5acab --- /dev/null +++ b/sem_3/Programm/TP2/exo13/pair.h @@ -0,0 +1 @@ +int pair ( unsigned int ); diff --git a/sem_3/Programm/TP2/exo13/spair b/sem_3/Programm/TP2/exo13/spair new file mode 100644 index 0000000..fe2dd14 Binary files /dev/null and b/sem_3/Programm/TP2/exo13/spair differ diff --git a/sem_3/Programm/TP2/exo13/spair.c b/sem_3/Programm/TP2/exo13/spair.c new file mode 100644 index 0000000..32fa224 --- /dev/null +++ b/sem_3/Programm/TP2/exo13/spair.c @@ -0,0 +1,11 @@ +#include +#include +#include "pair.h" +#include "impair.h" + +int main ( int argc, char ** argv) { + int param = atoi(argv[1]); + if (pair(param)) printf("%d est pair\n", param); + else printf("%d est impair\n", param); + return 0; +} diff --git a/sem_3/Programm/cours-hlin302.pdf b/sem_3/Programm/cours-hlin302.pdf new file mode 100644 index 0000000..12690ef Binary files /dev/null and b/sem_3/Programm/cours-hlin302.pdf differ diff --git a/sem_3/Programm/jeu_de_la_vie/JDV0-bis-main.cpp b/sem_3/Programm/jeu_de_la_vie/JDV0-bis-main.cpp new file mode 100644 index 0000000..e1ae237 --- /dev/null +++ b/sem_3/Programm/jeu_de_la_vie/JDV0-bis-main.cpp @@ -0,0 +1,14 @@ +#include +using namespace std; + +#include "JDV0-bis.h" + +int main(int argc, char** argv){ + + JeuDeLaVie JDV; + JDV.parseOptions(argc,argv); + JDV.run(4); + + return 0; +} + diff --git a/sem_3/Programm/jeu_de_la_vie/JDV0-bis.cpp b/sem_3/Programm/jeu_de_la_vie/JDV0-bis.cpp new file mode 100644 index 0000000..587c05a --- /dev/null +++ b/sem_3/Programm/jeu_de_la_vie/JDV0-bis.cpp @@ -0,0 +1,149 @@ +#include "JDV0-bis.h" +#include +#include +#include +#include +using namespace std; + + +void JeuDeLaVie::nettoie(std::string &s){ + size_t pos=s.find_first_of("#"); + s=s.substr(0,pos); + int beg=0,end=s.size()-1; + while(begbeg-1 && (s[end]==' ' || s[end]=='\t' )) end--; + s=s.substr(beg,end-beg+1); +} + + +bool JeuDeLaVie::findCleVal(std::string &s, std::string &s1,std::string &s2){ + nettoie(s); + if (s==string("")) return false; + size_t pos=s.find_first_of(":"); + if (pos==string::npos) { + cerr << "Le fichier est mal formé" << endl; + terminate(); + } + s1=s.substr(0,pos); + s2=s.substr(pos+1); + nettoie(s1); + nettoie(s2); + //cerr<<"Found cle/val -> "<< s1<< " and "< "< " << (++i < argc ? argv[i] : "Erreur"); + } else { + cout << "Cette option n'a pas été reconnue."; + opt_error = true; + } + cout << endl; + } + i++; + } + if (opt_error) { + cout << "Usage : " << argv[0] << " [Options]" << endl; + opts.print(); + terminate(); + } +} diff --git a/sem_3/Programm/jeu_de_la_vie/JDV0-bis.h b/sem_3/Programm/jeu_de_la_vie/JDV0-bis.h new file mode 100644 index 0000000..763111d --- /dev/null +++ b/sem_3/Programm/jeu_de_la_vie/JDV0-bis.h @@ -0,0 +1,38 @@ +#ifndef __JDV_H +#define __JDV_H + +#include "population-vivante-v2.h" +#include "tabOptions.h" + +#define HELP_ID 1 +#define VERSION_ID 2 +#define DIMENSION_ID 10 +#define PROBABILITY_ID 11 +#define CONFIG_ID 20 + + +class JeuDeLaVie { + private: + PopulationVivante POP; + TabOptions opts; + + void nettoie(std::string &s); + bool findCleVal(std::string &s, std::string &s1,std::string &s2); + void TraiteOption(const std::string &cle, const std::string &valeur, size_t num_ligne); + + public: + + JeuDeLaVie(); + + void loadConfig(std::string file); + void run(size_t); + void parseOptions(int argc, char** argv); + +}; + + + + + + +#endif diff --git a/sem_3/Programm/jeu_de_la_vie/arch/population.cpp b/sem_3/Programm/jeu_de_la_vie/arch/population.cpp new file mode 100644 index 0000000..5655e2f --- /dev/null +++ b/sem_3/Programm/jeu_de_la_vie/arch/population.cpp @@ -0,0 +1,145 @@ +#include +#include +#include +#include "population.h" +using namespace std; + +#define CHECK_BOUND(i,j) \ + if (i>=N || j>=N){ \ + std::cout<<"Accessing a Cell at ("< +#include +#include +#include "population_vivante.h" + +population_vivante::population_vivante(size_t x){ + if ( x > N ) { + std::cout<<" Erreur, taille de population trop grande"< +#include +using namespace std; + +Cellule::Cellule(): age(0), x(0), y(0), couleur(NOIR) { +} + +Cellule::Cellule(bool etat, unsigned int x, unsigned int y): + age(etat ? 1 : 0), x(x), y(y), couleur(etat ? BLEU : NOIR) { +} + +bool Cellule::getVivante() const { + return age; +} + +unsigned int Cellule::getX() const { + return x; +} + +unsigned int Cellule::getY() const { + return y; +} + +Cellule::Couleur Cellule::getCouleur() const { + return couleur; +} + +// Accesseurs en écriture +void Cellule::setX(unsigned int x) { + this->x = x; +} + +void Cellule::setY(unsigned int y) { + this->y = y; +} + +bool Cellule::estVoisine(const Cellule &c) const { + return age && + ((x - c.x) * (x - c.x) + (y - c.y) * (y - c.y) <= 2); +} + +void Cellule::print() const { + std::cout<<"("< "< + +class Cellule { + public: + + enum Couleur { + NOIR, + BLEU, + VERT, + ROUGE, + JAUNE, + NB_COULEURS + }; + + private: + size_t age; + unsigned int x, y; + Couleur couleur; + + public: + + // Constructeurs + Cellule(); // morte par défaut + Cellule(bool etat, unsigned int x, unsigned int y); + + // Accesseurs en lecture + bool getVivante() const; + unsigned int getX() const; + unsigned int getY() const; + Couleur getCouleur() const; + + // Accesseurs en écriture + void setX(unsigned int x); + void setY(unsigned int y); + void setVivante(bool etat); + + // renvoie vrai si la cellule courante est vivante et est voisine de c + bool estVoisine(const Cellule &c) const; + // affiche la cellule + void print() const; + + // spécifie qu'une cellule doit mourir au prochain tour du jeu (-> changement de couleur) + void doitMourir(); +}; + +// Renvoie vrai si la cellule est de la couleur passée en paramètre, faux sinon. +bool CelluleEstDeLaCouleur(const Cellule &cellule, Cellule::Couleur couleur); + +// Retourne la chaîne correspondant à la couleur passée en paramètre +std::string Couleur2String(Cellule::Couleur c); + +#endif diff --git a/sem_3/Programm/jeu_de_la_vie/option.cpp b/sem_3/Programm/jeu_de_la_vie/option.cpp new file mode 100644 index 0000000..65d2241 --- /dev/null +++ b/sem_3/Programm/jeu_de_la_vie/option.cpp @@ -0,0 +1,45 @@ +#include +#include "option.h" +#include + +using namespace std; + +/////////////////// +// Classe Option // +/////////////////// + +Option::Option(): id(-1), nom(), raccourci(), description(), type(AUCUN) {} + +Option::Option(int _id, const string &_nom, const string &_raccourci, + const string &_desc, Option::Type _type): + id(_id), nom(_nom), raccourci(_raccourci), description(_desc), type(_type) {} + +int Option::getId() const { return id; } +string Option::getName() const { return nom; } +string Option::getShortcut() const { return raccourci; } +string Option::getDescription() const { return description; } +Option::Type Option::getType() const { return type; } + +void Option::setId(int _id) { this->id = _id; } +void Option::setName(const string &name) { nom = name; } +void Option::setShortcut(const string &shortcut) { raccourci = shortcut; } +void Option::setDescription(const string &desc) { description = desc; } +void Option::setType(Option::Type t) { type = t; } + +void Option::print() const { + cout << nom << " (" << raccourci << ") " << Type2String(type) + << "\t" << description << endl; +} + +string Type2String(Option::Type t) { + string tmp; + switch (t) { + case Option::AUCUN: tmp = ""; break; + case Option::BOOLEEN: tmp = ""; break; + case Option::ENTIER: tmp = ""; break; + case Option::REEL: tmp = ""; break; + case Option::CHAR: tmp = ""; break; + case Option::CHAINE: tmp = ""; break; + } + return tmp; +} diff --git a/sem_3/Programm/jeu_de_la_vie/option.h b/sem_3/Programm/jeu_de_la_vie/option.h new file mode 100644 index 0000000..e420c4a --- /dev/null +++ b/sem_3/Programm/jeu_de_la_vie/option.h @@ -0,0 +1,47 @@ +#ifndef __OPTION_H +#define __OPTION_H + +#include + +class Option { + public: + enum Type { + AUCUN, + BOOLEEN, + ENTIER, + REEL, + CHAR, + CHAINE + }; + + private: + int id; + std::string nom, raccourci, description; + Type type; + + public: + Option(); + Option(int id, const std::string &nom, const std::string &raccourci, + const std::string &desc, Type type); + + // Accesseurs en lecture + int getId() const; + std::string getName() const; + std::string getShortcut() const; + std::string getDescription() const; + Type getType() const; + + // Accesseurs en écriture + void setId(int id); + void setName(const std::string &name); + void setShortcut(const std::string &shortcut); + void setDescription(const std::string &desc); + void setType(Type t); + + // Affichage + void print() const; +}; + +std::string Type2String(Option::Type t); + +#endif diff --git a/sem_3/Programm/jeu_de_la_vie/population-vivante-v2.cpp b/sem_3/Programm/jeu_de_la_vie/population-vivante-v2.cpp new file mode 100644 index 0000000..f59cb97 --- /dev/null +++ b/sem_3/Programm/jeu_de_la_vie/population-vivante-v2.cpp @@ -0,0 +1,184 @@ +#include +#include +#include +#include "population-vivante-v2.h" +using namespace std; + +#define CHECK_BOUND(i,j) \ + if (i>=N || j>=N){ \ + std::cout<<"Accessing a Cell at ("<setVivante(true); + } + } + else { + std::cerr<<"PopulationVivante: Erreur -> trop de cellule vivante pour NMAX="< +#include +#include "tabOptions.h" + +using namespace std; + +TabOptions::TabOptions(): opts(), nb_opts(0) {} + +void TabOptions::addOption(const Option &o) { + if (nb_opts == NMAX_OPTS) { + cerr << "Erreur: Impossible d'ajouter une nouvelle option." << endl + << " Nombre maximum d'option atteint"<< " (" << NMAX_OPTS << ")." + << endl; + terminate(); + } + + bool found = (getOptionIndex(o.getName()) != -1) || (getOptionIndex(o.getShortcut()) != -1); + + if (found) { + cerr << "Avertissement: L'identifiant " << o.getId() << " est déjà utilisé." + << endl; + } else { + opts[nb_opts] = o; + nb_opts++; + } +} + +void TabOptions::print() const { + cout << "Options :" << endl; + for (size_t i = 0; i < nb_opts; i++) { + opts[i].print(); + } +} + +int TabOptions::getOptionIndex(const string &opt) const { + bool found = false; + size_t i = 0; + while (!found && (i < nb_opts)) { + found = ((opts[i].getName() == opt) || (opts[i].getShortcut() == opt)); + i++; + } + return found ? i - 1 : -1; +} +// opt doit etre une option valide +int TabOptions::getOptionId(const std::string &opt) const { + int i = getOptionIndex(opt); + return (i>=0 ? opts[i].getId():-1); +} +// opt doit etre une option valide +bool TabOptions::optionHasArgument(const std::string &opt) const { + size_t i = getOptionIndex(opt); + return (opts[i].getType() != Option::AUCUN); +} +// opt doit etre une option valide +Option::Type TabOptions::optionArgumentType(const std::string &opt) const { + size_t i = getOptionIndex(opt); + return opts[i].getType(); +} diff --git a/sem_3/Programm/jeu_de_la_vie/tabOptions.h b/sem_3/Programm/jeu_de_la_vie/tabOptions.h new file mode 100644 index 0000000..cef8aaa --- /dev/null +++ b/sem_3/Programm/jeu_de_la_vie/tabOptions.h @@ -0,0 +1,22 @@ +#ifndef __TABOPTIONS_H__ +#define __TABOPTIONS_H__ + +#include +#include "option.h" + +#define NMAX_OPTS 100 +class TabOptions { + private: + Option opts[NMAX_OPTS]; + size_t nb_opts; + int getOptionIndex(const std::string &opt) const; + public: + TabOptions(); + void addOption(const Option &o); + void print() const; + int getOptionId(const std::string &opt) const; + bool optionHasArgument(const std::string &opt) const; + Option::Type optionArgumentType(const std::string &opt) const; +}; + +#endif -- cgit v1.2.3