diff options
Diffstat (limited to 'sem_3')
139 files changed, 4475 insertions, 0 deletions
diff --git a/sem_3/Programm/TP1/test b/sem_3/Programm/TP1/test Binary files differnew file mode 100644 index 0000000..8577d4f --- /dev/null +++ b/sem_3/Programm/TP1/test 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<iostream> + +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 Binary files differnew file mode 100644 index 0000000..3c36d84 --- /dev/null +++ b/sem_3/Programm/TP2/ex1/exo 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<iostream>
+#include"itv.h"
+
+float Itv::lenght () {
+ return bornesup-borneinf;
+}
+
+void Itv::afficher () {
+ std::cout<<"["<<borneinf<<","<<bornesup<<"]"<<std::endl;
+}
+
+bool Itv::appartient (float f) {
+ return f<=bornesup && f>=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<iostream>
+
+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"<<y <<"}"<<std::endl;
+}
+
+bool cell::estvoisineenVie (cell &cellule) {
+ if ( cellule.x == x + 1 || cellule.y == y + 1 || cellule.x == x - 1 || cellule.y == y - 1 ) {
+ if (cellule.statut) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+cell::cell ( int a, int b, bool c) {
+ x = a;
+ y = b;
+ statut = c;
+}
diff --git a/sem_3/Programm/TP2/ex1/jeudelaviemine/cell.h b/sem_3/Programm/TP2/ex1/jeudelaviemine/cell.h new file mode 100644 index 0000000..93b841e --- /dev/null +++ b/sem_3/Programm/TP2/ex1/jeudelaviemine/cell.h @@ -0,0 +1,24 @@ +enum color {
+ rouge,
+ vert,
+ noir,
+ jaune
+};
+
+class cell {
+private :
+ int x;
+ int y;
+ bool statut;
+ color couleur;
+public :
+ void setColor(color);
+ color getColor();
+ void setVivante (bool);
+ bool getVivante ();
+ int getX ();
+ int getY ();
+ void printcell () ;
+ cell(int,int,bool);
+ bool estvoisineenVie(cell&);
+};
diff --git a/sem_3/Programm/TP2/ex1/jeudelaviemine/main b/sem_3/Programm/TP2/ex1/jeudelaviemine/main Binary files differnew file mode 100644 index 0000000..c076b3e --- /dev/null +++ b/sem_3/Programm/TP2/ex1/jeudelaviemine/main diff --git a/sem_3/Programm/TP2/ex1/jeudelaviemine/main.cpp b/sem_3/Programm/TP2/ex1/jeudelaviemine/main.cpp new file mode 100644 index 0000000..02d6bcb --- /dev/null +++ b/sem_3/Programm/TP2/ex1/jeudelaviemine/main.cpp @@ -0,0 +1,25 @@ +#include<iostream>
+#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")<<std::endl;
+ std::cout<< (cell2.estvoisineenVie(cell1) ? "cell2 est voisine de cell1" : "cell2 n'est pas voisine de cell1")<<std::endl;
+ return 0;
+}
+
+void test_cell ( cell &cellule) {
+ cellule.printcell();
+}
+
+bool cell_est_couleur ( cell &cellule, color couleur) {
+ color act = cellule.getColor;
+ return (couleur == act);
+}
diff --git a/sem_3/Programm/TP2/ex1/main.cpp b/sem_3/Programm/TP2/ex1/main.cpp new file mode 100644 index 0000000..99a7321 --- /dev/null +++ b/sem_3/Programm/TP2/ex1/main.cpp @@ -0,0 +1,12 @@ +#include<iostream>
+#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 <stdlib.h>
+#include <stdio.h>
+
+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 Binary files differnew file mode 100644 index 0000000..a617d42 --- /dev/null +++ b/sem_3/Programm/TP2/exo10/main 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 <stdlib.h>
+#include <stdio.h>
+
+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 Binary files differnew file mode 100644 index 0000000..3aeee19 --- /dev/null +++ b/sem_3/Programm/TP2/exo11/main 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 --- /dev/null +++ b/sem_3/Programm/TP2/exo13/exo13.c 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 Binary files differnew file mode 100644 index 0000000..fe2dd14 --- /dev/null +++ b/sem_3/Programm/TP2/exo13/spair 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 <stdlib.h>
+#include <stdio.h>
+#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 Binary files differnew file mode 100644 index 0000000..12690ef --- /dev/null +++ b/sem_3/Programm/cours-hlin302.pdf 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 <iostream> +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 <cstdlib> +#include <iostream> +#include <fstream> +#include <exception> +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(beg<end+1 && (s[beg]==' ' || s[beg]=='\t' )) beg++; + while(end>beg-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 "<<s2<<endl; + return true; +} + +void JeuDeLaVie::TraiteOption(const string &cle, const string &valeur, size_t num_ligne){ + if (cle == "Dimension") { + POP.setDimension(atoi(valeur.c_str())); + POP.reset(); + } + if (cle == "Probability") { + POP.setProbability(atof(valeur.c_str())); + POP.reset(); + } + if (cle == "Cell") { + size_t x, y; + size_t pos = valeur.find_first_of("x, "); + if (pos == string::npos || valeur[pos] == '\0') { + cerr << "Le fichier est mal formé. Vérifiez la syntaxe de la ligne "<< num_ligne << endl; + } + else { + x = atoi(valeur.substr(0, pos).c_str()); + y = atoi(valeur.substr(pos).c_str()); + POP.birth(x,y); + } + } +} + + +void JeuDeLaVie::loadConfig(std::string file){ + ifstream input(file.c_str()); + string cle, valeur; + size_t num_ligne=0; + + if (!input.is_open()) { + cerr << "Le fichier " << file << " n'a pas pu être ouvert." << endl; + terminate(); + } + string line; + while (!input.eof()) { + getline(input,line); + //cout<<"reading line ("<<num_ligne<<") -> "<<line<<endl; + if (!input.eof()) { + if (findCleVal(line,cle,valeur)) + TraiteOption(cle,valeur,num_ligne); + } + num_ligne++; + } + input.close(); +} + +void JeuDeLaVie::run(size_t n) { + POP.print(); + for(size_t i=0;i<n;i++){ + POP=POP.next(); + POP.print(); + } +} + + +JeuDeLaVie::JeuDeLaVie() : POP(8,0.25) { + + opts.addOption(Option(HELP_ID, "--help", "-h", + "Affiche l'aide du programme", Option::AUCUN)); + opts.addOption(Option(VERSION_ID, "--version", "-v", + "Affiche la version du programme", Option::AUCUN)); + opts.addOption(Option(DIMENSION_ID, "--dimension", "-N", + "Initialise une matrice carrée de la dimension spécifiée", + Option::ENTIER)); + opts.addOption(Option(PROBABILITY_ID, "--probability", "-p", + "Probabilité d'une cellule d'être en vie au démarrage", + Option::REEL)); + opts.addOption(Option(CONFIG_ID, "--config", "-f", + "Charge la configuration initiale du jeu " + "à partir du fichier passé en paramètre", + Option::CHAINE)); +} + + +void JeuDeLaVie::parseOptions(int argc, char** argv){ + bool opt_error = false; + int i = 1; + while (!opt_error && i < argc) { + int x = opts.getOptionId(argv[i]); + switch (x) { + case HELP_ID: + cout << "usage " << argv[0] << " [Options]" << endl; + opts.print(); return; + case VERSION_ID: + cout << "Programme " << argv[0] << " version 0.0.0" << endl; + return; + case DIMENSION_ID: + POP.setDimension(atoi(argv[++i])); + break; + case PROBABILITY_ID: + POP.setProbability(atof(argv[++i])); + break; + case CONFIG_ID: + loadConfig(argv[++i]); + break; + default: + if (opts.optionHasArgument(argv[i])) { + cout << "L'option " << argv[i] << " a été trouvée."; + cout << " Elle attend un argument de type " + << Type2String(opts.optionArgumentType(argv[i])); + cout << " => " << (++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 <iostream> +#include <cstdlib> +#include <exception> +#include "population.h" +using namespace std; + +#define CHECK_BOUND(i,j) \ + if (i>=N || j>=N){ \ + std::cout<<"Accessing a Cell at ("<<i<<","<<j<<") out of range..." \ + << " Aborting"<<std::endl; \ + std::terminate(); \ + } + + +size_t Population::nb_voisins_vivants(size_t ci, size_t cj) const { + size_t cpt=0; + size_t imin,imax,jmin,jmax; + imin = ci==0?ci:ci-1; + imax = ci==(N-1)?ci:ci+1; + jmin = cj==0?cj:cj-1; + jmax = cj==(N-1)?cj:cj+1; + + for (size_t i = imin ; i <= imax ; i++) { + for (size_t j = jmin ; j <= jmax ; j++) { + if (T[i][j].getVivante()) { + cpt++; + } + } + } + return cpt - (T[ci][cj].getVivante() ? 1 : 0); +} + +void Population::updateColors() { + //calcule les cellules vivantes qui vont mourir + for (size_t i = 0 ; i < N ; i++) { + for (size_t j = 0 ; j < N ; j++) { + size_t voisin=nb_voisins_vivants(i, j); + if (voisin !=3 && voisin!=2 && T[i][j].getVivante()) + T[i][j].doitMourir(); + } + } +} + + + +Population::Population() { + for (size_t i = 0 ; i < N ; i++) { + for (size_t j = 0 ; j < N ; j++) { + T[i][j].setX(i); + T[i][j].setY(j); + T[i][j].setVivante(false); + } + } +} + +void Population::init(size_t n) { + srand(time(NULL)); + if (nb_vivants()==0){ + size_t i,j; + for (size_t k = 0 ; k < n ; k++) { + do { + i=rand()% N; + j=rand()% N; + } while ((T[i][j]).getVivante()); + T[i][j].setVivante(true); + } + updateColors(); + } +} + + +size_t Population::nb_cellules(Cellule::Couleur c) const { + size_t cpt=0; + for (size_t i = 0 ; i < N ; i++) { + for (size_t j = 0 ; j < N ; j++) { + if (CelluleEstDeLaCouleur(T[i][j],c)) { + cpt++; + } + } + } + return cpt; +} + +size_t Population::nb_vivants() const { return N*N-nb_morts();} +size_t Population::nb_deces() const { return nb_cellules(Cellule::ROUGE)+nb_cellules(Cellule::JAUNE);} +size_t Population::nb_morts() const { return nb_cellules(Cellule::NOIR);} +size_t Population::nb_naissances() const { return nb_cellules(Cellule::BLEU);} + + +Cellule Population::getCelluleCopie(size_t i, size_t j) const { + CHECK_BOUND(i,j); + return T[i][j]; +} + +const Cellule& Population::getCellule(size_t i, size_t j) const{ + CHECK_BOUND(i,j); + return T[i][j]; +} + +void Population::printCell(size_t i, size_t j) const { + CHECK_BOUND(i,j); + T[i][j].print(); +} + +void Population::kill(size_t i, size_t j) { + CHECK_BOUND(i,j); + T[i][j].setVivante(false); +} + +void Population::birth(size_t i, size_t j) { + CHECK_BOUND(i,j); + T[i][j].setVivante(true); +} + +void Population::print() const { + for (size_t i = 0 ; i < N + 2 ; i++) { + cout<<"X"; + } + cout<<endl; + for (size_t i = 0 ; i < N ; i++) { + cout<<"X"; + for (size_t j = 0 ; j < N ; j++) { + //T[i][j].print(); + cout<<Couleur2String(T[i][j].getCouleur()); + } + cout<<"X"<<endl; + } + for (size_t i = 0 ; i < N + 2 ; i++) { + cout<<"X"; + } + cout<<endl; +} + +Population Population::next() const { + Population POP(*this); + for (size_t i = 0 ; i < N ; i++) { + for (size_t j = 0 ; j < N ; j++) { + size_t voisin=nb_voisins_vivants(i,j); + (POP.T[i][j]).setVivante(voisin ==3 || (voisin==2 && T[i][j].getVivante())); + } + } + POP.updateColors(); + return POP; +} + diff --git a/sem_3/Programm/jeu_de_la_vie/arch/population.h b/sem_3/Programm/jeu_de_la_vie/arch/population.h new file mode 100644 index 0000000..9f5ad98 --- /dev/null +++ b/sem_3/Programm/jeu_de_la_vie/arch/population.h @@ -0,0 +1,53 @@ +#ifndef __POPULATION_H +#define __POPULATION_H +#include "cellule.h" + +#define N 5 + +class Population { + + private: + Cellule T[N][N]; + + // retourne le nbr de voisins vivants de la cellule à (i,j) + size_t nb_voisins_vivants(size_t, size_t) const; + + //retourne le nbr de cellule d'une couleur donnée + size_t nb_cellules(Cellule::Couleur) const; + + // Mise à jour des couleurs des cellules mourantes + void updateColors(); + + public: + + // constructeur d'une population vide (sur une grille NxN) + Population(); + + // création de n cellules vivantes aléatoires (uniquement si population vide) + void init(size_t); + + // accesseurs en interrogation + size_t nb_vivants() const; + size_t nb_deces() const; + size_t nb_morts() const; + size_t nb_naissances() const; + + // accesseurs en lecture d'une cellule + Cellule getCelluleCopie(size_t i, size_t j) const; + const Cellule& getCellule(size_t i, size_t j) const; + + // accesseurs en modification + void kill(size_t i, size_t j); + void birth(size_t i, size_t j); + + // affichage d'une cellule + void printCell(size_t i, size_t j) const; + // affichage de la population + void print() const; + + // calcul de la population suivante + Population next() const; + +}; + +#endif diff --git a/sem_3/Programm/jeu_de_la_vie/arch/population_vivante.cpp b/sem_3/Programm/jeu_de_la_vie/arch/population_vivante.cpp new file mode 100644 index 0000000..93b328a --- /dev/null +++ b/sem_3/Programm/jeu_de_la_vie/arch/population_vivante.cpp @@ -0,0 +1,42 @@ +#include <iostream>
+#include <cstdlib>
+#include <exception>
+#include "population_vivante.h"
+
+population_vivante::population_vivante(size_t x){
+ if ( x > N ) {
+ std::cout<<" Erreur, taille de population trop grande"<<std::endl;
+ }
+ nmax = x;
+ vivantes=0;
+}
+
+void population_vivante::birth(unsigned int x, unsigned int y) {
+ if (vivantes < nmax){
+ Cellule tmp(true, x,y);
+ pop[vivantes]= tmp;
+ vivantes++;
+}
+else{
+ std::cout<<"Erreur, toutes les cellules sont deja vivantes!"
+}
+}
+void population_vivante::death(unsigned int x, unsigned int y){
+ for (int i =0; i < vivantes; i ++){
+ if ((pop[i].getX == x) && (pop[i].getY==y)) {
+ pop[i].setVivante(false);
+ for ( int j = i; j < vivantes-1; j ++ ){
+ pop[j]= pop[j+1];
+ }
+ i = vivantes;
+ vivantes--;
+ }
+ }
+}
+const Cellule& copiecell(unsigned int x, unsigned int y){
+ for(int i=0; i< vivantes; i ++){
+ if ((pop[i].getX == x) && (pop[i].getY==y)) {
+ return pop[i];
+ }
+ }
+ }
diff --git a/sem_3/Programm/jeu_de_la_vie/arch/population_vivante.h b/sem_3/Programm/jeu_de_la_vie/arch/population_vivante.h new file mode 100644 index 0000000..5b960b6 --- /dev/null +++ b/sem_3/Programm/jeu_de_la_vie/arch/population_vivante.h @@ -0,0 +1,18 @@ +#ifndef __POPULATION_VIVANTE_H +#define __POPULATION_VIVANTE_H + +#include "cellule.h" + +#define N 5 +class population_vivante { +private: + size_t nmax; + cellule pop[N*N]; + size_t vivantes; +public: + population_vivante(size_t); + void death(unsigned int x, unsigned int y); + void birth(unsigned int x, unsigned int y); + cellule& copiecell(unsigned int x, unsigned int y); +}; +#endif diff --git a/sem_3/Programm/jeu_de_la_vie/cellule.cpp b/sem_3/Programm/jeu_de_la_vie/cellule.cpp new file mode 100644 index 0000000..7611e7a --- /dev/null +++ b/sem_3/Programm/jeu_de_la_vie/cellule.cpp @@ -0,0 +1,95 @@ +#include "cellule.h" +#include <iostream> +#include <string> +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<<"("<<x<<","<<y<<") - > "<<Couleur2String(couleur)<<std::endl; +} + +void Cellule::setVivante(bool etat) { + if (etat) { + couleur = age++ ? VERT : BLEU; + } else { + age = 0; + couleur = NOIR; + } +} + +void Cellule::doitMourir() { + if (age) { // La cellule est vivante et va mourir + couleur = (couleur == BLEU ? JAUNE : ROUGE); + } +} + +bool CelluleEstDeLaCouleur(const Cellule &cellule, Cellule::Couleur couleur) { + return (cellule.getCouleur() == couleur); +} + +string Couleur2String(Cellule::Couleur c) { + string res; + switch (c) { + case Cellule::NOIR: + res = "\033[1;30mX\033[0m"; //"noire"; + break; + case Cellule::BLEU: + res = "\033[1;34mX\033[0m";//"bleue"; + break; + case Cellule::VERT: + res = "\033[1;32mX\033[0m";//"verte"; + break; + case Cellule::ROUGE: + res = "\033[1;31mX\033[0m";//"rouge"; + break; + case Cellule::JAUNE: + res = "\033[1;33mX\033[0m";//"jaune"; + break; + default: + res = "non définie."; + cerr << "Erreur:" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ + << ":Couleur non définie. Les couleurs possibles sont:" << endl; + for (Cellule::Couleur i = Cellule::NOIR; + i != Cellule::NB_COULEURS; + i = (Cellule::Couleur) (((int) i)+1)) { + cerr << "- " << Couleur2String(i) << endl; + } + } + return res; +} diff --git a/sem_3/Programm/jeu_de_la_vie/cellule.h b/sem_3/Programm/jeu_de_la_vie/cellule.h new file mode 100644 index 0000000..5ad6ef5 --- /dev/null +++ b/sem_3/Programm/jeu_de_la_vie/cellule.h @@ -0,0 +1,55 @@ +#ifndef __CELLULE_H +#define __CELLULE_H + +#include <string> + +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 <iostream> +#include "option.h" +#include <string> + +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 = "<booléen>"; break; + case Option::ENTIER: tmp = "<entier>"; break; + case Option::REEL: tmp = "<réel>"; break; + case Option::CHAR: tmp = "<caractère>"; break; + case Option::CHAINE: tmp = "<chaîne>"; 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 <string> + +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 <iostream> +#include <cstdlib> +#include <exception> +#include "population-vivante-v2.h" +using namespace std; + +#define CHECK_BOUND(i,j) \ + if (i>=N || j>=N){ \ + std::cout<<"Accessing a Cell at ("<<i<<","<<j<<") out of range ... aborting"<<std::endl; \ + std::terminate(); \ + } \ + +const Cellule* PopulationVivante::at(size_t i, size_t j) const { + for (size_t k = 0 ; k < alive ; k++) { + if ((T[k].getX() == i) && (T[k].getY() == j)) { + return T+k; + } + } + return NULL; +} + +Cellule* PopulationVivante::at(size_t i, size_t j) { + for (size_t k = 0 ; k < alive ; k++) { + if ((T[k].getX() == i) && (T[k].getY() == j)) { + return T+k; + } + } + return NULL; +} + +size_t PopulationVivante::nb_voisins_vivants(size_t ci, size_t cj) const { + size_t cpt=0; + size_t imin,imax,jmin,jmax; + imin = ci==0?ci:ci-1; + imax = ci==(N-1)?ci:ci+1; + jmin = cj==0?cj:cj-1; + jmax = cj==(N-1)?cj:cj+1; + + for (size_t i = imin ; i <= imax ; i++) { + for (size_t j = jmin ; j <= jmax ; j++) { + if (at(i,j) != NULL) { + cpt++; + } + } + } + return cpt - (at(ci,cj) != NULL ? 1 : 0); +} + +void PopulationVivante::updateColors() { + //calcule les cellules vivantes qui vont mourir + for (size_t i = 0; i < alive; i++) { + size_t voisin=nb_voisins_vivants(T[i].getX(), T[i].getY()); + if ((voisin != 2) && (voisin != 3)) T[i].doitMourir(); + } +} + +PopulationVivante::PopulationVivante(size_t n, float prob) : alive(0), N(n), probability(prob) { + reset(); +} + + +size_t PopulationVivante::nb_cellules(Cellule::Couleur c) const { + size_t cpt=0; + for (size_t i = 0 ; i < alive ; i++) { + if (CelluleEstDeLaCouleur(T[i],c)) { + cpt++; + } + } + return cpt; +} + +size_t PopulationVivante::nb_vivants() const { return N*N-nb_morts();} +size_t PopulationVivante::nb_deces() const { return nb_cellules(Cellule::ROUGE)+nb_cellules(Cellule::JAUNE);} +size_t PopulationVivante::nb_morts() const { return nb_cellules(Cellule::NOIR);} +size_t PopulationVivante::nb_naissances() const { return nb_cellules(Cellule::BLEU);} + + + +Cellule PopulationVivante::getCelluleCopie(size_t i, size_t j) const { + CHECK_BOUND(i,j); + const Cellule* ptr=at(i,j); + if (ptr==NULL) { + return Cellule(false,i,j); + } else { + return *ptr; + } +} + + + +void PopulationVivante::printCell(size_t i, size_t j) const { + CHECK_BOUND(i,j); + getCelluleCopie(i,j).print(); +} + +void PopulationVivante::kill(size_t i, size_t j) { + CHECK_BOUND(i,j); + const Cellule* ptr=at(i,j); + if (ptr!=NULL) { + size_t k=ptr-T; // retrouve la position dans le tableau + for ( ; k < alive - 1 ; k++) { + T[k]=T[k+1]; + } + alive--; + } +} + +void PopulationVivante::birth(size_t i, size_t j) { + if (alive+1<NMAX){ + CHECK_BOUND(i,j); + Cellule* ptr=at(i,j); + if (ptr==NULL) { + T[alive]=Cellule(true,i,j); + alive++; + } + else{ + ptr->setVivante(true); + } + } + else { + std::cerr<<"PopulationVivante: Erreur -> trop de cellule vivante pour NMAX="<<NMAX<<std::endl; + std::cerr<<"aborting...\n"; + std::terminate(); + } +} + +void PopulationVivante::print() const { + for (size_t i = 0; i < N + 2 ; i++) { + cout << "X"; + } + cout<<endl; + for (size_t i = 0 ; i < N ; i++) { + cout<<"X"; + for (size_t j = 0 ; j < N ; j++) { + cout<<Couleur2String(getCelluleCopie(i,j).getCouleur()); + } + cout<<"X"<<endl; + } + for (size_t i = 0 ; i < N + 2 ; i++) { + cout<<"X"; + } + cout<<endl; +} + +PopulationVivante PopulationVivante::next() const { + PopulationVivante POP(*this); + for (size_t i = 0 ; i < N ; i++) { + for (size_t j = 0 ; j < N ; j++) { + size_t voisin=nb_voisins_vivants(i,j); + if ((voisin == 3) || ((voisin == 2) && (at(i,j) != NULL))) { + POP.birth(i,j); + } else { + POP.kill(i,j); + } + } + } + POP.updateColors(); + return POP; +} + + +/// NEW STUFF TD4 + +size_t PopulationVivante::getDimension() const {return N;} + +float PopulationVivante::getProbability() const {return probability;} + +void PopulationVivante::setDimension(size_t n) {N=n; reset();} + +void PopulationVivante::setProbability(float p) {probability=p; reset();} + + +void PopulationVivante::reset() { + alive=0; + srand(time(NULL)); + for (size_t i = 0 ; i < N ; i++) { + for (size_t j = 0 ; j < N ; j++) { + if (((rand() % 10000) / 10000.) <= probability) { + birth(i,j); + } + } + } + updateColors(); +} diff --git a/sem_3/Programm/jeu_de_la_vie/population-vivante-v2.h b/sem_3/Programm/jeu_de_la_vie/population-vivante-v2.h new file mode 100644 index 0000000..2ba155c --- /dev/null +++ b/sem_3/Programm/jeu_de_la_vie/population-vivante-v2.h @@ -0,0 +1,60 @@ +#ifndef __POPULATION_VIVANTE_H +#define __POPULATION_VIVANTE_H +#include "cellule.h" + +#define NMAX 10000 + +class PopulationVivante { + private: + Cellule T[NMAX]; + size_t alive; + size_t N; + float probability; + + // retourne le nbr de voisins vivants de la cellule à (i,j) + size_t nb_voisins_vivants(size_t, size_t) const; + + // access to cell at (i,j) if not alive get NULL + const Cellule* at(size_t i, size_t j)const; + Cellule* at(size_t i, size_t j); + // Mise à jour des couleurs des cellules mourantes + void updateColors(); + + size_t nb_cellules(Cellule::Couleur c) const; + + public: + + // construction d'une n-population avec une probabilité fixée. + PopulationVivante(size_t n, float prob); + + // accesseurs en interrogation + size_t nb_vivants() const; + size_t nb_deces() const; + size_t nb_morts() const; + size_t nb_naissances() const; + size_t getDimension() const; + float getProbability() const; + + + // accesseurs en lecture d'une cellule + Cellule getCelluleCopie(size_t i, size_t j) const; + + // accesseurs en modification + void kill(size_t i, size_t j); + void birth(size_t i, size_t j); + void setDimension(size_t n); + void setProbability(float p); + + // affichage d'une cellule + void printCell(size_t i, size_t j) const; + // affichage de la population + void print() const; + + // Re-création de la population + void reset(); + + // calcul de la population suivante + PopulationVivante next() const; +}; + +#endif diff --git a/sem_3/Programm/jeu_de_la_vie/tabOptions.cpp b/sem_3/Programm/jeu_de_la_vie/tabOptions.cpp new file mode 100644 index 0000000..0e78679 --- /dev/null +++ b/sem_3/Programm/jeu_de_la_vie/tabOptions.cpp @@ -0,0 +1,58 @@ +#include <iostream> +#include <exception> +#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 <string> +#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 diff --git a/sem_3/SYSTEME/TP1/JelesAime b/sem_3/SYSTEME/TP1/JelesAime new file mode 100644 index 0000000..a4cd10e --- /dev/null +++ b/sem_3/SYSTEME/TP1/JelesAime @@ -0,0 +1 @@ +IM ON THE HIGHWAY TO HELL diff --git a/sem_3/SYSTEME/TP1/mesChanteursPreferes b/sem_3/SYSTEME/TP1/mesChanteursPreferes new file mode 100644 index 0000000..a4cd10e --- /dev/null +++ b/sem_3/SYSTEME/TP1/mesChanteursPreferes @@ -0,0 +1 @@ +IM ON THE HIGHWAY TO HELL diff --git a/sem_3/SYSTEME/TP2/ex6/param b/sem_3/SYSTEME/TP2/ex6/param Binary files differnew file mode 100644 index 0000000..944bb79 --- /dev/null +++ b/sem_3/SYSTEME/TP2/ex6/param diff --git a/sem_3/SYSTEME/TP2/ex6/param.c b/sem_3/SYSTEME/TP2/ex6/param.c new file mode 100644 index 0000000..c321752 --- /dev/null +++ b/sem_3/SYSTEME/TP2/ex6/param.c @@ -0,0 +1,12 @@ +#include<stdlib.h> +#include<stdio.h> + +int main ( int argc, char **argv) { + printf("Nombre d'arguments : %d\n", argc); + int i = 1; + for (i; i < argc; i ++ ) { + printf("%s\n",argv[i]); + } +return 0; +} + diff --git a/sem_3/SYSTEME/TP2/ex7/moyenne b/sem_3/SYSTEME/TP2/ex7/moyenne Binary files differnew file mode 100644 index 0000000..3e75ffc --- /dev/null +++ b/sem_3/SYSTEME/TP2/ex7/moyenne diff --git a/sem_3/SYSTEME/TP2/ex7/moyenne.c b/sem_3/SYSTEME/TP2/ex7/moyenne.c new file mode 100644 index 0000000..6a420d8 --- /dev/null +++ b/sem_3/SYSTEME/TP2/ex7/moyenne.c @@ -0,0 +1,14 @@ +#include<stdlib.h> +#include<stdio.h> + +int main ( int argc, char **argv) { + int i = 1; + double moy = 0; + for (i; i < argc; i ++ ) { + moy += atof(argv[i]); + } +moy = moy/(i-1); +printf("%f \n", moy ); +return 0; +} + diff --git a/sem_3/SYSTEME/TP2/ex9/strsplit b/sem_3/SYSTEME/TP2/ex9/strsplit Binary files differnew file mode 100644 index 0000000..65fe687 --- /dev/null +++ b/sem_3/SYSTEME/TP2/ex9/strsplit diff --git a/sem_3/SYSTEME/TP2/ex9/strsplit.c b/sem_3/SYSTEME/TP2/ex9/strsplit.c new file mode 100644 index 0000000..69c68e5 --- /dev/null +++ b/sem_3/SYSTEME/TP2/ex9/strsplit.c @@ -0,0 +1,54 @@ +#include<stdlib.h> +#include<stdio.h> + +//char ** strsplit ( char*,char); +char ** strsplit ( char * fichier, char sep ) { + printf("entree dans strsplit"); + int nbsep = 0; + int cpt = 0; + while ( fichier[cpt] != '\0' ) { + nbsep += (fichier[cpt] == sep ? 1 : 0); + cpt ++; + } + printf("%d bloc differents",cpt); + int i = 0, offset = 0, offsetchar = 0; + char ** tab = malloc((cpt + 1)*sizeof(char*)) ; + printf("tab init"); + //tab[cpt] = NULL; + printf("%p", tab[cpt+1]); + for ( i =0; i < cpt+1; i ++ ) { + tab[i] = malloc ( 100 * sizeof(char)); + } + i =0; + cpt = 0; + while ( fichier[i] != '\0' ) { + if (fichier[i] != sep) { + tab[offset][offsetchar] = fichier[i]; + offsetchar ++; + cpt ++; + } + else { + tab[offset][offsetchar]='/0'; + tab[offset] = realloc ( tab[offset], (cpt) * sizeof(char)); + offset++; + offsetchar = 0; + cpt = 0 ; + } + } +return tab; +} + + +int main (int argc, char ** argv) { +int i=0,cpt=0; +printf("jusqu'ici tout va bien"); +char ** tableau = strsplit(argv[1], argv[2][0]); +while (tableau[i]!=NULL) { + while (tableau[i][cpt]!='\0') { + printf("%c",tableau[i][cpt]); + cpt ++; + } + printf("\n"); +i ++; +} +return 0;} diff --git a/sem_3/SYSTEME/TP2/impair.c b/sem_3/SYSTEME/TP2/impair.c new file mode 100644 index 0000000..f61f5bc --- /dev/null +++ b/sem_3/SYSTEME/TP2/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/SYSTEME/TP2/impair.h b/sem_3/SYSTEME/TP2/impair.h new file mode 100644 index 0000000..196468b --- /dev/null +++ b/sem_3/SYSTEME/TP2/impair.h @@ -0,0 +1 @@ +int impair(unsigned int);
diff --git a/sem_3/SYSTEME/TP2/pair.c b/sem_3/SYSTEME/TP2/pair.c new file mode 100644 index 0000000..05b9a0a --- /dev/null +++ b/sem_3/SYSTEME/TP2/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/SYSTEME/TP2/pair.h b/sem_3/SYSTEME/TP2/pair.h new file mode 100644 index 0000000..2b5acab --- /dev/null +++ b/sem_3/SYSTEME/TP2/pair.h @@ -0,0 +1 @@ +int pair ( unsigned int );
diff --git a/sem_3/SYSTEME/TP2/spair b/sem_3/SYSTEME/TP2/spair Binary files differnew file mode 100644 index 0000000..fe2dd14 --- /dev/null +++ b/sem_3/SYSTEME/TP2/spair diff --git a/sem_3/SYSTEME/TP2/spair.c b/sem_3/SYSTEME/TP2/spair.c new file mode 100644 index 0000000..32fa224 --- /dev/null +++ b/sem_3/SYSTEME/TP2/spair.c @@ -0,0 +1,11 @@ +#include <stdlib.h>
+#include <stdio.h>
+#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/SYSTEME/TP3/HUFFMAN/Makefile b/sem_3/SYSTEME/TP3/HUFFMAN/Makefile new file mode 100644 index 0000000..63886ef --- /dev/null +++ b/sem_3/SYSTEME/TP3/HUFFMAN/Makefile @@ -0,0 +1,9 @@ +all : dehuf.o huf.o + gcc -Wall -ansi -pedantic -std=c99 dehuf.o -o dehuf -lm + gcc -Wall -ansi -pedantic -std=c99 distrib.o -o huf -lm +dehuf.o : dehuf.c + gcc -Wall -ansi -pedantic -std=c99 -c dehuf.c +huf.o : distrib.c + gcc -Wall -ansi -pedantic -std=c99 -c distrib.c +clean : + rm *.o diff --git a/sem_3/SYSTEME/TP3/HUFFMAN/compact.py b/sem_3/SYSTEME/TP3/HUFFMAN/compact.py new file mode 100644 index 0000000..0d57b91 --- /dev/null +++ b/sem_3/SYSTEME/TP3/HUFFMAN/compact.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3
+
+import os,sys,re
+from subprocess import call
+
+def parcours (cible,fichierdir,init):
+ if os.path.isdir(cible):
+ liste=os.listdir(cible)
+ for fichier in liste :
+ fichier = cible+"/"+fichier
+ parcours(fichier,fichierdir,init)
+ else :
+ tmp = open(cible,'rb')
+ if init[0]=="/" :
+ fichierdir.write(b"\n--"+bytes(cible[len(re.search("(^\/.*\/).+",init).group(0))+1:],'UTF-8')+b"--\n")
+ else :
+ fichierdir.write(b"\n--"+bytes(cible,"UTF-8")+b"--\n")
+ print(cible)
+ byte=tmp.read()
+ fichierdir.write(byte)
+ tmp.close()
+
+if len(sys.argv)!= 2 :
+ print("Parametres incorrects, syntaxe : ./compact.py fichier\n")
+ exit()
+cible = sys.argv[1]
+fichier = open(".compactageencours",'ab')
+parcours(cible,fichier,cible)
+destination = re.search("(\w+\.?\w+)$",sys.argv[1]).group(1)+".comp"
+call(["./huf", ".compactageencours", destination])
+call(["rm",".compactageencours"])
+fichier.close()
diff --git a/sem_3/SYSTEME/TP3/HUFFMAN/decompact.py b/sem_3/SYSTEME/TP3/HUFFMAN/decompact.py new file mode 100644 index 0000000..1cc3bc3 --- /dev/null +++ b/sem_3/SYSTEME/TP3/HUFFMAN/decompact.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3
+
+import os, sys,re
+from subprocess import call
+
+def creerdossier(path):
+ result =re.split("/",path)
+ for i in range(len(result)-1):
+ if i >= 1 :
+ result[i]= result[i-1]+"/"+result[i]
+ if not (os.path.exists(result[i])):
+ call(["mkdir",result[i]])
+
+def decompactdistant(fichier, fichierdest):
+ os.system("./dehuf "+fichier+" > .decompactencours")
+ premierdos = fichierdest
+ call(["mkdir",premierdos])
+ decompact = open(".decompactencours","r")
+ destfile=decompact
+ for line in decompact.readlines()[1:]:
+ tmp = line.encode()
+ if line[0]=="-" and line[1]=="-":
+ estuneentete=re.search("^--(.*)--$",line)
+ if estuneentete:
+ destfile.close()
+ creerdossier(premierdos+"/"+estuneentete.group(1))
+ destfile=open(premierdos+"/"+estuneentete.group(1),"w")
+ else :
+ destfile.write(line)
+
+def decompacthere(fichier):
+ os.system("./dehuf "+fichier+" > .decompactencours")
+ premierdos = re.search("(\w+)\.?\w*.comp$",fichier).group(1)
+ call(["mkdir",premierdos])
+ decompact = open(".decompactencours","r")
+ destfile=decompact
+ for line in decompact.readlines()[1:]:
+ tmp = line.encode()
+ if line[0]=="-" and line[1]=="-":
+ estuneentete=re.search("^--(.*)--$",tmp)
+ if estuneentete:
+ destfile.close()
+ creerdossier(premierdos+"/"+estuneentete.group(1))
+ destfile=open(premierdos+"/"+estuneentete.group(1),"w")
+ else :
+ destfile.write(line)
+
+if len(sys.argv)==2:
+ decompacthere(sys.argv[1])
+elif len(sys.argv)==3:
+ decompactdistant(sys.argv[1],sys.argv[2])
+else:
+ print("Parametres incorrects, syntaxe : ./decompact.py fichiercomp [destination] \n (Destination est optionnel)")
+ exit()
+call(["rm",".decompactencours"])
diff --git a/sem_3/SYSTEME/TP3/HUFFMAN/dehuf.c b/sem_3/SYSTEME/TP3/HUFFMAN/dehuf.c new file mode 100644 index 0000000..7b264e1 --- /dev/null +++ b/sem_3/SYSTEME/TP3/HUFFMAN/dehuf.c @@ -0,0 +1,150 @@ +#include<stdio.h> +#include<stdlib.h> +#include<math.h> + +typedef struct table table; +struct table { + unsigned int taille; + unsigned int * taillecode; + char * carac; + char ** code; +}; + +table * gettable(FILE*); +int getcarac(char *,int, table *,char *); +void getdata(FILE *, table *); +void printtabcomp ( table * ); +void supprimerTable(table * ); + + +int main ( int argc, char ** argv){ + if (argc!=2) { + printf("Nombre d'arguments incorrects, syntaxe : \"./dehuf \"fichiercomp\"\"\n"); + return 1; + } + FILE * fichier = fopen(argv[1], "rb"); + if (fichier == NULL) { + printf("Erreur, l'ouverture du fichier source à rencontré une erreur, verifiez que vous avez les droits en lecture sur le fichier.\n"); + } + table * donneecompression = gettable(fichier); + //printtabcomp(donneecompression); + getdata(fichier, donneecompression); + supprimerTable(donneecompression); + return 0; +} + + +void supprimerTable(table * tablecod){ + for (unsigned int i = 0; i < tablecod->taille; i ++){ + free(tablecod->code[i]); + } + free(tablecod->taillecode); + free(tablecod->carac); + free(tablecod); +} +table * gettable(FILE* fichier){ + int temp=0; + table * tablecodage = malloc(sizeof(table)); + tablecodage->taille = fgetc(fichier); + if (tablecodage->taille == 0) tablecodage->taille=256; + tablecodage->taillecode=malloc(sizeof(int)*tablecodage->taille); + tablecodage->carac=malloc(sizeof(char)*tablecodage->taille); + tablecodage->code=malloc(sizeof(char*)*tablecodage->taille); + int caracrestant = tablecodage->taille; + int caracint =0; + while (caracrestant>0){ + tablecodage->taillecode[tablecodage->taille-caracrestant]=fgetc(fichier); + tablecodage->code[tablecodage->taille-caracrestant]=malloc(sizeof(char)*tablecodage->taillecode[tablecodage->taille-caracrestant]); + for (int i =0; i < tablecodage->taillecode[tablecodage->taille-caracrestant] ; i ++){ + + if ( i%8 == 0){ + caracint =fgetc(fichier); + } + if (caracint >= (float)pow(2,7-(i%8))){ + tablecodage->code[tablecodage->taille-caracrestant][i]='1'; + caracint -= pow(2,7-(i%8)); + } + else { + tablecodage->code[tablecodage->taille-caracrestant][i]='0'; + } + } + temp=fgetc(fichier); + tablecodage->carac[tablecodage->taille-caracrestant]=(char)temp; + caracrestant --; + } + return tablecodage; +} +int getcarac(char * code,int taille, table * tablecodage,char * carac){ + if (taille == 0){ + return 0; + } + int i =0; + int trouve = 0; + while ( i < tablecodage->taille && !trouve){ + if (tablecodage->taillecode[i]==taille){ + int j =0; + int cestpaslui = 0; + while ( j < taille && !cestpaslui){ + if ( code[j] != tablecodage->code[i][j]){ + cestpaslui=1; + } + else j ++; + } + trouve= !cestpaslui ? 1 : 0; + } + if (!trouve) i ++; + } + if (trouve){ + *carac=tablecodage->carac[i]; + return 1; + } + else return 0; +} +void printtabcomp ( table * tabcomp){ + for (int i =0; i < tabcomp->taille; i ++){ + if (tabcomp->carac[i]==(char)10) { + printf("Carac = LF"); + } + else if (tabcomp->carac[i]==(char)13) { + printf("Carac = CR"); + } + else printf("Carac = %c", tabcomp->carac[i]); + printf(", taille chemin = %d, chemin = ", tabcomp->taillecode[i]); + for (int j =0; j < tabcomp->taillecode[i]; j ++){ + printf("%c",tabcomp->code[i][j]); + } + printf("\n"); + } +} +void getdata(FILE * fichier, table * donneecompression){ + int currentcarac=fgetc(fichier); + int nextcarac=fgetc(fichier); + int lastcarac=fgetc(fichier); + int cpt=0; + int taille=0; + char * code = malloc(0); + char carac; + int trouve=0; + while (lastcarac!=EOF){ + while ( !(trouve=getcarac(code,taille,donneecompression,&carac))/*&&lastcarac!=EOF*/){ + if ( cpt == 8){ + currentcarac=nextcarac; + nextcarac=lastcarac; + lastcarac=fgetc(fichier); + cpt =0; + } + taille ++; + code=realloc(code,sizeof(char)*taille); + if (currentcarac>=pow(2,7-cpt)){ + code[taille-1]='1'; + currentcarac-=pow(2,7-cpt); + } + else code[taille-1]='0'; + cpt ++; + } + printf("%c", carac); + taille = 0; + code=realloc(code,0); + } + printf("\n"); +} diff --git a/sem_3/SYSTEME/TP3/HUFFMAN/distrib.c b/sem_3/SYSTEME/TP3/HUFFMAN/distrib.c new file mode 100644 index 0000000..3ae45b1 --- /dev/null +++ b/sem_3/SYSTEME/TP3/HUFFMAN/distrib.c @@ -0,0 +1,357 @@ +#include<stdio.h> +#include<stdlib.h> +#include<math.h> + +typedef struct proba proba; +struct proba { + char * carac; + int * nb_carac; + float * proba; + int taille; + int somme; +}; +typedef struct branche branche; +struct branche { + char noeud; + branche * filsg; + branche * filsd; +}; +typedef struct doublet doublet; +struct doublet{ + int a; + int b; +}; +typedef struct table table; +struct table { + unsigned int taille; + unsigned int * taillecode; + char * carac; + char ** code; + unsigned int indice[256]; +}; +typedef struct buffer buffer; +struct buffer { + unsigned int taille; + char contenu; +}; + +void loading(int, FILE *,float *); +void forceprintbuffer(buffer *,FILE *); +void supprimerTable(table *); +void ecrirecomp(FILE *,FILE *,table *,buffer *,int ); +void videbuffer(buffer *); +void ajouterbuffer(buffer*, char,FILE *); +void printcaraccode(table *,char,FILE *, buffer*); +void printchemin (char *, int, FILE *, buffer *); +void parcoursarbre ( branche *, char *, int, FILE *, table *, buffer *); +table * ecrireArbre(FILE *, branche*, int,buffer *); +void afficheTab(proba *); +void supprimerArbre(branche *); +branche* creerArbre(char , branche * , branche * ); +int estdanstab (char *,int,char); +void creertab (proba *, FILE *); +branche* creerHuff(proba*); +doublet deuxpluspetits(proba *); +void aff(branche *, int ); +void printinfofinales(table *, FILE *, FILE *); + + +int main (int argc, char ** argv) { + if (argc != 3) { + printf("Erreur, la syntaxe est la suivante : ./huffhuff [source] [destination]"); + return -1; + } + FILE * fichier = fopen(argv[1], "r"); + if (fichier == NULL) { + printf("Erreur, l'ouverture du fichier source à rencontré une erreur, verifiez que vous avez les droits en lecture sur le fichier."); + } + FILE * fichierdest = fopen(argv[2],"wb"); + if (fichierdest == NULL) { + printf("Erreur, l'ouverture du fichier de destination à rencontré une erreur."); + return -2; + } + fseek(fichier,0,SEEK_END); + int size = ftell(fichier); + rewind(fichier); + proba tab; + printf("Le fichier %s fait %d octets.\n",argv[1],size); + creertab (&tab, fichier); + afficheTab(&tab); + branche * Arbre = creerHuff(&tab); + free(tab.carac); + free(tab.nb_carac); + free(tab.proba); + buffer * buf = malloc(sizeof(buffer)); + videbuffer(buf); + table * tablecodage = ecrireArbre(fichierdest, Arbre, tab.taille,buf); + ecrirecomp(fichier,fichierdest,tablecodage,buf,size); + printinfofinales(tablecodage,fichier,fichierdest); + supprimerArbre(Arbre); + supprimerTable(tablecodage); + free(buf); + fclose(fichierdest); + fclose( fichier); + return 0; +} + + +void printinfofinales(table * tablecode, FILE * source, FILE * destination){ + int somme=0; + for (int i = 0; i < tablecode->taille;i++){ + somme+=tablecode->taillecode[i]; + } + float moy = (float)somme/(float)tablecode->taille; + printf("Fini ! \n"); + printf("Longueur moyenne du codage : %2.2f bits;", moy); + fseek(source,0,SEEK_END); + fseek(destination,0,SEEK_END); + int taillesource = ftell(source); + int taillecible = ftell(destination); + printf (" Taille d'origine : %d; Taille compressée : %d; Soit un gain de %3.2f %%\n", taillesource,taillecible,100-(float)taillecible*100/(float)taillesource); +} +void supprimerTable(table * tablecod){ + for (unsigned int i = 0; i < tablecod->taille; i ++){ + free(tablecod->code[i]); + } + free(tablecod->taillecode); + free(tablecod->carac); + free(tablecod); +} +void loading(int taille, FILE * fichier, float * anciennevaleur){ + int current = ftell(fichier)-1; + float avancement = current*100/taille; + if (current == 0){ + *anciennevaleur=0; + printf("["); + fflush(stdout); + } + if (*anciennevaleur+10 <= avancement){ + printf("##"); + fflush(stdout); + *anciennevaleur=avancement; + } + if (current == taille-2){ + printf("##]"); + fflush(stdout); + } + +} +void ecrirecomp(FILE * fichier,FILE * fichierdest,table * tablecodage, buffer * buf, int size){ + fseek(fichier,0,SEEK_SET); + int current=fgetc(fichier); + float * anciennevaleur=malloc(sizeof(float)); + *anciennevaleur=0; + while(current!=EOF){ + printcaraccode(tablecodage,(char)current,fichierdest,buf); + loading(size,fichier,anciennevaleur); + current =fgetc(fichier); + } + char remplissage = (char) 8-buf->taille; + forceprintbuffer(buf,fichierdest); + fwrite(&remplissage,sizeof(char),1,fichierdest); + free(buf); +} +void videbuffer(buffer * buf){ + buf->taille=0; + buf->contenu = 0; +} +void ajouterbuffer(buffer* buf, char carac,FILE * destination){ + char tmp='1'; + if ( buf->taille < 8){ + if ( carac == tmp)buf->contenu+=pow(2,7-buf->taille); + buf->taille++; + } + if (buf->taille == 8) { + fwrite(&buf->contenu,sizeof(char),1,destination); + videbuffer(buf); + fflush(destination); + } +} +void forceprintbuffer(buffer * buf,FILE * destination){ + if ( buf->taille>0){ + fwrite(&buf->contenu,sizeof(char),1,destination); + videbuffer(buf); + } +} +void printcaraccode(table* tablecodage,char carac,FILE * fichierdest, buffer * buf){ + unsigned int i =0; + i=tablecodage->indice[(unsigned char)carac]; + for (unsigned int j=0; j < tablecodage->taillecode[i];j++){ + ajouterbuffer(buf,tablecodage->code[i][j],fichierdest); + } +} +void printchemin (char * chemin, int taille, FILE *destination,buffer * buf){ + char taillechar = (char)taille; + fwrite(&taillechar, sizeof(char),1,destination); + for (int i =0; i < taille; i ++){ + ajouterbuffer(buf,chemin[i],destination); + }; + forceprintbuffer(buf, destination); +} +branche* creerHuff(proba*prob){ + branche * arbrehuf[prob->taille]; + for ( int i =0; i <= prob->taille; i ++){ + arbrehuf[i]= creerArbre(prob->carac[i], NULL, NULL); + } + doublet indices = deuxpluspetits(prob); + while (indices.b!=-1) { + arbrehuf[indices.a] = creerArbre (0, arbrehuf[indices.a],arbrehuf[indices.b]); + prob->proba[indices.a]+=prob->proba[indices.b]; + prob->proba[indices.b]=0; + indices = deuxpluspetits(prob); + } + return arbrehuf[indices.a]; +} +void parcoursarbre ( branche * Arbre, char * chemin, int taille, FILE * destination, table * tabcode, buffer * buf){ + if ( Arbre->filsd == NULL && Arbre->filsg==NULL ){ + printchemin(chemin, taille, destination, buf); + fwrite(&Arbre->noeud,sizeof(char),1,destination); + char * code = malloc(taille*sizeof(char)); + tabcode->taille+=1; + tabcode->code= realloc(tabcode->code,tabcode->taille*sizeof(char*)); + tabcode->carac=realloc(tabcode->carac,tabcode->taille*sizeof(char)); + tabcode->taillecode=realloc(tabcode->taillecode,tabcode->taille*sizeof(unsigned int)); + tabcode->carac[tabcode->taille-1]=Arbre->noeud; + tabcode->taillecode[tabcode->taille-1]=taille; + tabcode->indice[(unsigned char)Arbre->noeud]=tabcode->taille-1; + for (int i =0; i < taille; i ++){ + code[i]=chemin[i]; + } + tabcode->code[tabcode->taille-1]=code; + if (Arbre->noeud==(char)10) { + printf("Carac = LF"); + } + else if (Arbre->noeud==(char)13) { + printf("Carac = CR"); + } + else printf("Carac = %c", Arbre->noeud); + printf(", taille chemin = %d, chemin = ", taille); + for (int i =0; i < taille; i ++){ + printf("%c",chemin[i]); + } + printf("\n"); + } + else{ + int newtaille= taille + 1; + chemin = realloc(chemin, newtaille*sizeof(char)); + if (Arbre->filsg!=NULL){ + chemin[newtaille-1]='0'; + parcoursarbre ( Arbre->filsg, chemin, newtaille, destination, tabcode,buf ); + } + if (Arbre->filsd!=NULL){ + chemin[newtaille-1]='1'; + parcoursarbre ( Arbre->filsd, chemin, newtaille, destination, tabcode,buf); + } + } +} +table * ecrireArbre(FILE * destination, branche* arbre, int taille,buffer * buf){ + char taille2 = (char)taille; + table * tabcode = malloc(sizeof(table)); + tabcode->taille = 0; + tabcode->taillecode= malloc(0); + tabcode->code=malloc(0); + tabcode->carac=malloc(0); + fwrite(&taille2,sizeof(char),1,destination); + char * chemin = malloc(0); + parcoursarbre(arbre, chemin, 0, destination, tabcode,buf); + free(chemin); + fflush(destination); + return tabcode; +} +branche* creerArbre(char carac, branche * ssag, branche * ssad){ + branche * tmp = malloc(sizeof(branche)); + tmp->noeud= carac; + tmp->filsd= ssad; + tmp->filsg=ssag; + return tmp; +} +void supprimerArbre(branche * arbre){ + branche * gauche = arbre->filsg; + branche * droite = arbre->filsd; + if ( gauche != NULL){ + supprimerArbre(gauche); + } + if (droite!=NULL){ + supprimerArbre(droite); + } + if (droite==NULL && gauche == NULL) { + free(arbre); + } +} +void creertab (proba * tab, FILE * fichier){ + tab->carac = malloc(0); + tab->nb_carac = malloc (0); + tab->taille = 0; + tab->somme=0; + int caracint = 0; + char caracchar = 0; + int indice = -1; + caracint= fgetc(fichier); + while (caracint != EOF ) { + caracchar = (char)caracint; + tab->somme ++; + indice = estdanstab(tab->carac, tab->taille, caracchar); + if ( indice != -1) { + tab->nb_carac[indice]++; + } + else { + tab->taille ++; + tab->carac=realloc(tab->carac,tab->taille*(sizeof(char))); + tab->nb_carac=realloc(tab->nb_carac,tab->taille*(sizeof(int))); + tab->carac[tab->taille-1]= caracchar; + tab->nb_carac[tab->taille-1]= 1; + } + caracint = fgetc(fichier); + } + tab->proba=malloc(tab->taille*(sizeof(float))); + for (int i =0; i<tab->taille;i++){ + tab->proba[i]= (float)tab->nb_carac[i]/(float)tab->somme; + } +} +int estdanstab(char * tab, int n, char x) { + int i=0; + int ret=0; + while (i<n && !ret) { + if (tab[i]==x) ret = 1; + i ++; + } + return ret ? i-1 : -1; +} +void afficheTab(proba * prob){ + for (int i =0; i < prob->taille; i ++) { + if (prob->carac[i]==(char)10) { + printf("LF | %1.3f \n", prob->proba[i]); + } + if (prob->carac[i]==(char)13) { + printf("CR | %1.3f \n", prob->proba[i]); + } + else { + printf("%c | %1.3f \n", prob->carac[i], prob->proba[i]); + } + + } + printf("Le fichier comporte %d caracteres differents\n", prob->taille); +} +doublet deuxpluspetits(proba * prob) { //renvoie les indices des deux plus petits float du tableau + doublet ret; + ret.a= -1; + ret.b=-1; + float aval,bval; + aval = 2; + bval = 2; + for (int i =0; i< prob->taille; i ++){ + if ( prob->proba[i]!=0){ + if ( prob->proba[i]< aval){ + ret.b= ret.a; + bval=aval; + ret.a=i; + aval=prob->proba[i]; + } + else if (prob->proba[i]<bval){ + ret.b=i; + bval=prob->proba[i]; + } + } + } + return ret; +} diff --git a/sem_3/SYSTEME/TP3/HUFFMAN/minirapport.odt b/sem_3/SYSTEME/TP3/HUFFMAN/minirapport.odt Binary files differnew file mode 100644 index 0000000..f03ca37 --- /dev/null +++ b/sem_3/SYSTEME/TP3/HUFFMAN/minirapport.odt diff --git a/sem_3/SYSTEME/TP3/HUFFMAN/readme.txt b/sem_3/SYSTEME/TP3/HUFFMAN/readme.txt new file mode 100644 index 0000000..f6fd3d3 --- /dev/null +++ b/sem_3/SYSTEME/TP3/HUFFMAN/readme.txt @@ -0,0 +1,16 @@ +Compresseur Huffman de Gaspard Coulet,
+"make all" pour compiler huf et dehuf,
+./huf source destination
+./dehuf fichiercompressé
+
+Pas de bug ou de soucis connu jusque là , le traitement prend apparemment un peu de temps, la faute à une optimisation peut être pas assez poussée. Le programme n'affiche pas l'arbre de huffman, car je n'ai pas eu le temps de me pencher sur la représentation
+de l'arbre, en revanche, il affiche les chemin de chacun des caractères, ce qui est, en soit, une représentation de l'arbre.
+
+Compacteur :
+
+aide :
+
+"./compact.py source"
+Compacte source dans source.comp à l'endroit ou le script est exécuté.
+"./decompact.py source [destination]"
+Décompacte le dossier compressé source, si destination est précisé, décompresse dedans.
diff --git a/sem_3/SYSTEME/TP4/ex22/exo b/sem_3/SYSTEME/TP4/ex22/exo Binary files differnew file mode 100644 index 0000000..9bb5490 --- /dev/null +++ b/sem_3/SYSTEME/TP4/ex22/exo diff --git a/sem_3/SYSTEME/TP4/ex22/exo.c b/sem_3/SYSTEME/TP4/ex22/exo.c new file mode 100644 index 0000000..5701746 --- /dev/null +++ b/sem_3/SYSTEME/TP4/ex22/exo.c @@ -0,0 +1,23 @@ +#include<stdlib.h> +#include<stdio.h> + +int main ( int argc, char ** argv) { + if (argc != 2) { + printf("Erreur, la syntaxe est la suivante : ./huffhuff [nomdufichier]"); + return -1; + } + FILE * fichier = fopen(argv[1], "r"); + if (fichier == NULL) { + printf("Erreur, l'ouverture du fichier à rencontré une erreur, verifiez que vous avez les droits en lecture sur le fichier."); + } + int caraccount=0; + int caracint; + caracint= fgetc(fichier); + while (caracint != EOF ) { + caraccount++; + caracint = fgetc(fichier); + } + printf("%d\n",caraccount); + fclose(fichier); + return 0; +} diff --git a/sem_3/SYSTEME/TP4/impair.c b/sem_3/SYSTEME/TP4/impair.c new file mode 100644 index 0000000..f61f5bc --- /dev/null +++ b/sem_3/SYSTEME/TP4/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/SYSTEME/TP4/impair.h b/sem_3/SYSTEME/TP4/impair.h new file mode 100644 index 0000000..196468b --- /dev/null +++ b/sem_3/SYSTEME/TP4/impair.h @@ -0,0 +1 @@ +int impair(unsigned int);
diff --git a/sem_3/SYSTEME/TP4/impair.o b/sem_3/SYSTEME/TP4/impair.o Binary files differnew file mode 100644 index 0000000..c243e3c --- /dev/null +++ b/sem_3/SYSTEME/TP4/impair.o diff --git a/sem_3/SYSTEME/TP4/libpair.a b/sem_3/SYSTEME/TP4/libpair.a Binary files differnew file mode 100644 index 0000000..b9799de --- /dev/null +++ b/sem_3/SYSTEME/TP4/libpair.a diff --git a/sem_3/SYSTEME/TP4/libpair.so.1 b/sem_3/SYSTEME/TP4/libpair.so.1 Binary files differnew file mode 100644 index 0000000..1f7fd3d --- /dev/null +++ b/sem_3/SYSTEME/TP4/libpair.so.1 diff --git a/sem_3/SYSTEME/TP4/pair.c b/sem_3/SYSTEME/TP4/pair.c new file mode 100644 index 0000000..05b9a0a --- /dev/null +++ b/sem_3/SYSTEME/TP4/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/SYSTEME/TP4/pair.h b/sem_3/SYSTEME/TP4/pair.h new file mode 100644 index 0000000..2b5acab --- /dev/null +++ b/sem_3/SYSTEME/TP4/pair.h @@ -0,0 +1 @@ +int pair ( unsigned int );
diff --git a/sem_3/SYSTEME/TP4/pair.o b/sem_3/SYSTEME/TP4/pair.o Binary files differnew file mode 100644 index 0000000..7f6ccff --- /dev/null +++ b/sem_3/SYSTEME/TP4/pair.o diff --git a/sem_3/SYSTEME/TP4/spair.c b/sem_3/SYSTEME/TP4/spair.c new file mode 100644 index 0000000..410bcbf --- /dev/null +++ b/sem_3/SYSTEME/TP4/spair.c @@ -0,0 +1,10 @@ +#include <stdlib.h>
+#include <stdio.h>
+#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/SYSTEME/TP4/spair2 b/sem_3/SYSTEME/TP4/spair2 Binary files differnew file mode 100644 index 0000000..fe2dd14 --- /dev/null +++ b/sem_3/SYSTEME/TP4/spair2 diff --git a/sem_3/SYSTEME/TP4/spair4 b/sem_3/SYSTEME/TP4/spair4 Binary files differnew file mode 100644 index 0000000..43441e1 --- /dev/null +++ b/sem_3/SYSTEME/TP4/spair4 diff --git a/sem_3/SYSTEME/TP5/analyse_options.py b/sem_3/SYSTEME/TP5/analyse_options.py new file mode 100644 index 0000000..27c195b --- /dev/null +++ b/sem_3/SYSTEME/TP5/analyse_options.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3
+import sys
+import re
+import os
+if len(sys.argv) != 2 :
+ print("Options incorectes")
+os.getenv("HOME")
+fd = open("/home/Lenain/.bashrc","r")
+content = fd.readlines()
+fd.close()
+for lines in content :
+ if re.search("^-",sys.argv[1]) :
+ if re.search("a",sys.argv[1]) :
+ opta = re.search("^[\t ]*alias[ \t]*(\w+)=(.+)", lines)
+ if opta :
+ print(opta.group(1),"=", opta.group(2))
+ if re.search("p",sys.argv[1]) :
+ opta = re.search("^PATH=$PATH:(.*)", lines)
+ if opta :
+ print(opta.group(1))
diff --git a/sem_3/SYSTEME/TP5/bonjour_v1.py b/sem_3/SYSTEME/TP5/bonjour_v1.py new file mode 100644 index 0000000..a877b61 --- /dev/null +++ b/sem_3/SYSTEME/TP5/bonjour_v1.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python3
+import sys
+print("Bonjour", sys.argv[1],"!")
diff --git a/sem_3/SYSTEME/TP6/comptagefichier.py b/sem_3/SYSTEME/TP6/comptagefichier.py new file mode 100644 index 0000000..6b97463 --- /dev/null +++ b/sem_3/SYSTEME/TP6/comptagefichier.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3
+
+import os, sys,re
+listetypefichier = {};
+def parcours (repertoire):
+ print("Je suis dans "+repertoire)
+ liste=os.listdir(repertoire)
+ for fichier in liste :
+ fichier = repertoire+"/"+fichier
+ if os.path.isdir(fichier):
+ parcours(fichier)
+ else :
+ recherche = re.search("(\.\w+)$", fichier)
+ if recherche :
+ if recherche.group(1) in listetypefichier :
+ listetypefichier[recherche.group(1)]+=1
+ else :
+ listetypefichier[recherche.group(1)]=1;
+ else :
+ if "pas de suffixe" in listetypefichier :
+ listetypefichier["pas de suffixe"]+=1
+ else :
+ listetypefichier["pas de suffixe"]=1
+
+parcours(sys.argv[1])
+total = 0;
+for cle in listetypefichier.keys() :
+ print(cle+" : ", listetypefichier[cle])
+ total += listetypefichier[cle]
+print("TOTAL : ",total)
diff --git a/sem_3/SiteWeb/index.html b/sem_3/SiteWeb/index.html new file mode 100644 index 0000000..370365f --- /dev/null +++ b/sem_3/SiteWeb/index.html @@ -0,0 +1,21 @@ + +<!DOCTYPE html> +<html lang="fr"> + <head> + <meta charset="utf-8"> + <title>Gaspard Coulet</title> + <link rel="stylesheet" href="./style.css"> + </head> + <body> + <h1 id="titre"> Site Web réalisé dans le cadre de l'enseignement de culture generale</br> outils de base en informatique</h1> + <div class="Cadre"> + <a class="lien" href="./tp1/index.html"><img class="image" alt="Image du premer site web realisé en TP" src="photo1.png">TP1</a> + <a class="lien" href="./tp2/index.html"><img class="image" src="photo2.png" alt="Image du second site web realisé en TP">TP2</a> + <a class="lien" href="./tp3/index.html"><img class="image" src="photo3.png" alt="Image d'une des page traitement de texte realisées en TP">TP3</a> + <a class="lien" href="./tp4/index.html"><img src="photo4.png" class="image" alt="Image des classeurs realisés en TP">TP4</a> + <a class="lien" href="./tp5/index.html"><img src="photo5.jpg" class="image" alt="Image du diapo realisée en TP">TP5</a> + </div> + <div class="Cadre"><p></p></div> + <footer> <p> Par : Gaspard Coulet</p><p> Contact : <a href="mailto:gaspard.coulet@etu.umontpellier.fr"> gaspard.coulet@etu.umontpellier.fr</p></footer> + </body> +</html> diff --git a/sem_3/SiteWeb/photo.png b/sem_3/SiteWeb/photo.png Binary files differnew file mode 100644 index 0000000..8ed1b43 --- /dev/null +++ b/sem_3/SiteWeb/photo.png diff --git a/sem_3/SiteWeb/photo1.png b/sem_3/SiteWeb/photo1.png Binary files differnew file mode 100644 index 0000000..394fd84 --- /dev/null +++ b/sem_3/SiteWeb/photo1.png diff --git a/sem_3/SiteWeb/photo2.png b/sem_3/SiteWeb/photo2.png Binary files differnew file mode 100644 index 0000000..87fdde8 --- /dev/null +++ b/sem_3/SiteWeb/photo2.png diff --git a/sem_3/SiteWeb/photo3.png b/sem_3/SiteWeb/photo3.png Binary files differnew file mode 100644 index 0000000..ddfefb7 --- /dev/null +++ b/sem_3/SiteWeb/photo3.png diff --git a/sem_3/SiteWeb/photo4.png b/sem_3/SiteWeb/photo4.png Binary files differnew file mode 100644 index 0000000..9bdcfa9 --- /dev/null +++ b/sem_3/SiteWeb/photo4.png diff --git a/sem_3/SiteWeb/photo5.jpg b/sem_3/SiteWeb/photo5.jpg Binary files differnew file mode 100644 index 0000000..53695c3 --- /dev/null +++ b/sem_3/SiteWeb/photo5.jpg diff --git a/sem_3/SiteWeb/photo5.png b/sem_3/SiteWeb/photo5.png Binary files differnew file mode 100644 index 0000000..21c1261 --- /dev/null +++ b/sem_3/SiteWeb/photo5.png diff --git a/sem_3/SiteWeb/style.css b/sem_3/SiteWeb/style.css new file mode 100644 index 0000000..afef246 --- /dev/null +++ b/sem_3/SiteWeb/style.css @@ -0,0 +1,103 @@ +html{ + height: 100%; +} +body { + background-color: rgb(100, 100, 100); + position: relative; + height: 100%; +} +.Cadre { + background-color: rgb(50,50,50); + border-radius: 10px; + width:75%; + text-align:left; + margin:auto; + margin-top: 2%; + padding:1% 1% 1% 1%; + color:White; +} +.image { + width: 97%; + margin-top : 2%; +} +footer { + text-align:left; + position: absolute; + color:White; + left:0; + width: 99.5%; + margin-top:2%; + background-color: rgb(30,30,30); + border-radius:10px; + padding-left:1%; +} +.lien { + display: inline-block; + width: 17%; + height: 98%; + text-align: center; + padding: auto; + margin: 1% 1% 1% 1%; + background-color: rgb(30,30,30); + border-radius: 5px; +} +.lientp1 { + display: inline-block; + width: 30%; + height: 98%; + text-align: center; + padding: auto; + margin: 1% 1% 1% 1%; + background-color: rgb(30,30,30); + border-radius: 5px; +} +.lientp2 { + display: inline-block; + width: 30%; + height: 98%; + text-align: center; + padding: auto; + margin: 1% 1% 1% 1%; + background-color: rgb(30,30,30); + border-radius: 5px; +} +.lientp3 { + display: inline-block; + width: 47%; + height: 98%; + text-align: center; + padding: auto; + margin: 1% 1% 1% 1%; + background-color: rgb(30,30,30); + border-radius: 5px; +} +.lientp4 { + display: inline-block; + width: 47%; + height: 98%; + text-align: center; + padding: auto; + margin: 1% 1% 1% 1%; + background-color: rgb(30,30,30); + border-radius: 5px; +} +.lientp5 { + display: inline-block; + width: 30%; + height: 98%; + text-align: center; + padding: auto; + margin: 1% 1% 1% 1%; + background-color: rgb(30,30,30); + border-radius: 5px; +} +#titre { + background-color:rgb(80,80,80); + border-radius: 10px; + margin:auto; + padding:1% 1% 1% 1%; + text-align: center; + width:66%; + color: White; + text-decoration:underline; +} diff --git a/sem_3/SiteWeb/tp1/Thumbs.db b/sem_3/SiteWeb/tp1/Thumbs.db Binary files differnew file mode 100644 index 0000000..8442228 --- /dev/null +++ b/sem_3/SiteWeb/tp1/Thumbs.db diff --git a/sem_3/SiteWeb/tp1/index.html b/sem_3/SiteWeb/tp1/index.html new file mode 100644 index 0000000..12209d4 --- /dev/null +++ b/sem_3/SiteWeb/tp1/index.html @@ -0,0 +1,43 @@ +<!DOCTYPE html>
+<html lang="fr">
+<head>
+ <meta charset="utf-8">
+ <title>Gaspard Coulet</title>
+ <link rel="stylesheet" href="../style.css">
+</head>
+<body>
+ <h1 id="titre"> TP1</h1>
+ <div class="Cadre">
+ <a class="lientp1" href="../index.html"><img class="image" alt="Image de l'acceuil" src="../photo.png">Acceuil</a>
+ <a class="lientp1" href="./pp.html" target = "_blank"><img class="image" alt="Image du premer site web realisé en TP1" src="../photo1.png">Site 1</a>
+ <a class="lientp1" href="./table.html" target = "_blank"><img class="image" src="./phototable.png" alt="Image du second site web realisé en TP1">Site tableau</a>
+ </div>
+ <div class="Cadre">
+ <h2> Notes et réponses aux questions :</h2><p>La commande tree affiche l'arborescence des fichiers du repertoire courant ( récursif ), avec le parametre
+ a, affiche aussi les fichiers cachés, avec le parametre d, affiche seulement les dossiers.</p>
+ <p>
+ La commande cd permet de se deplacer dans le systeme de fichier.
+ ".." est un raccourci pour acceder au repertoire parent dans l'arborescence.
+ Le parametre a de la commande ls permet d'afficher les fichiers cachés.
+ </p><p>
+ "for lettre in {a..e}; do for annee in {2010..2015}; do mkdir "archiveÂ-$lettre-Â$annee" ; done; done"
+ créée 25 dossiers nommés selon le type "archive-a-2010" jusqu'à "archive-e-2015".
+ </p><p>
+ Afin de trouver un fichier commencant par la lettre a et ne comprenant pas la lettre e, on utilisera la
+ commande : " ls | grep ^a | grep -v e"
+ </p><p>
+ Dans la commande "ls -a | more " affiche le contenu du repertoire courant ( fichier cachés compris )
+ de maniere a le lire ligne par ligne, c'est a ce derniers effet qu'est utile la seconde partie de la commande.
+ </p><p>
+ Dans un fichier html, la casse n'a aucune importance, le contenu de la balise title est en fait le titre de
+ l'onglet, les balises br sont des retours à la ligne, !... sont des commentaires, le © est le symbole
+ copyright, la suppression des balises fermantes html, body et head n'a aucune influence sur l'affichage de la page.</p><p>
+ La suppression des balises ouvrantes n'a pas plus d'effet.
+ En retirant la balise fermante h2, tout le texte suivant dans la page s'affiche comme le texte originellement
+ present entre les deux balises. Par ailleurs, en modifiant les dimensions de la fenetre, on remarque que
+ la page se reorganise dynamiquement.</p>
+
+ </p></div>
+ <footer> <p> Par : Gaspard Coulet</p><p> Contact : <a href="mailto:gaspard.coulet@etu.umontpellier.fr"> gaspard.coulet@etu.umontpellier.fr</p></footer>
+ </body>
+ </html>
diff --git a/sem_3/SiteWeb/tp1/photo1.jpg b/sem_3/SiteWeb/tp1/photo1.jpg Binary files differnew file mode 100644 index 0000000..fde363f --- /dev/null +++ b/sem_3/SiteWeb/tp1/photo1.jpg diff --git a/sem_3/SiteWeb/tp1/photo2.jpg b/sem_3/SiteWeb/tp1/photo2.jpg Binary files differnew file mode 100644 index 0000000..4bc54ba --- /dev/null +++ b/sem_3/SiteWeb/tp1/photo2.jpg diff --git a/sem_3/SiteWeb/tp1/phototable.png b/sem_3/SiteWeb/tp1/phototable.png Binary files differnew file mode 100644 index 0000000..4d84ed9 --- /dev/null +++ b/sem_3/SiteWeb/tp1/phototable.png diff --git a/sem_3/SiteWeb/tp1/pp.html b/sem_3/SiteWeb/tp1/pp.html new file mode 100644 index 0000000..0320eae --- /dev/null +++ b/sem_3/SiteWeb/tp1/pp.html @@ -0,0 +1,47 @@ +<html> + <head> +<title>Ceci est un test d'HLSE305 </title> +</head> + +<body bgcolor="000000" text="FFFFFF"> +<h2>Page Personnelle</h2> +<ul> +<li><a href="#p1"> Partie 1 </a></li> +<li><a href="#p2"> Partie 2 </a></li> +<li><a href="#p3"> Partie 3 </a></li> +<li><a href="#p4"> Partie 4 </a></li> +<li><a href="#p5"> Partie 5 </a></li> +</ul> + +<p> Pour le site de la fac, <a href="http://www.umontpellier.fr/"> Cliquez ici</a></p> +<p> Pour m'envoyer un mail, <a href="mailto:gaspard.coulet@etu.umontpellier.fr"> Cliquez ici</a></p> +<p> <a name="p1"> +Titre Principal +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus accumsan ultrices scelerisque. Integer laoreet aliquam nulla, ut lacinia enim tincidunt eu. Vestibulum egestas ligula turpis, et feugiat mi finibus id. Nunc ipsum lacus, finibus varius interdum consequat, vulputate sit amet nulla. Aliquam quis gravida sem. Sed elementum, nunc sed dictum consequat, dui nunc tempor velit, vel accumsan <a href="https://www.flickr.com/"><img src='./photo1.jpg' align="right" width="236" height="156" border="2"> </a>ex felis sed ipsum. Integer semper orci erat, vel pharetra ante sagittis nec. Proin volutpat interdum mi, sit amet suscipit ex mattis vitae. Nullam suscipit eget velit in ultrices. In pellentesque at lorem eu finibus. In vulputate egestas lorem, quis commodo nisl iaculis at. Aenean at velit mattis, volutpat tellus et, luctus lectus. Cras bibendum et nunc rutrum tincidunt. +</p> + +<p> <a name="p2"> +Titre secondaire +In quis egestas metus, nec malesuada orci. Quisque ac tempor odio. Pellentesque convallis malesuada bibendum. Aenean imperdiet rutrum ultricies. In leo urna, auctor vel elit quis, accumsan convallis augue. Maecenas non turpis lacinia, <em>malesuada dolor a</em>, imperdiet purus. Suspendisse condimentum tortor at consequat malesuada. +</p> +<p> <a name="p3"> +Titre secondaire +Quisque gravida dictum sagittis. Phasellus laoreet tellus ligula, fermentum porta dolor lobortis ac. Vestibulum eget porttitor magna. Duis lobortis mauris et justo pretium, laoreet viverra lorem pulvinar. Aenean sagittis ultrices fermentum. In hac habitasse platea dictumst. <strong>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse sit amet nisi non lorem hendrerit dictum. Aenean tincidunt erat ac lacus commodo interdum sit amet et magna</strong>. Aenean eu nulla accumsan, vestibulum neque id, tincidunt velit. Aenean vel mi ipsum. Integer in augue justo. Aenean bibendum dignissim ligula. Suspendisse diam nisl, tincidunt vel nibh nec, tincidunt venenatis arcu. +</p> + +<p> <a name="p4"> +Titre secondaire +Nulla nec lorem vel felis finibus imperdiet. Donec congue eleifend quam, a pretium libero sagittis a. Donec vel libero vel risus dictum rutrum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eros arcu, dignissim quis tellus vitae, cursus viverra metus. Duis efficitur, turpis nec rutrum fringilla, lacus sem viverra massa, a faucibus lectus diam non sapien. Nullam eget neque efficitur est tincidunt mattis eget at lacus. Duis eleifend eros neque, ac feugiat felis sodales nec. Aenean vitae nisi vulputate, malesuada velit eu, sagittis libero. Etiam volutpat vulputate quam ut tempus. Ut nec tempor dui. +</p> + +<p> <a name="p5"> +Titre secondaire +Cras vitae neque sapien. Ut lobortis ligula ac aliquam sagittis. Aliquam quis porttitor risus. Duis faucibus varius tellus, in tincidunt ipsum auctor a. Ut condimentum magna at dui faucibus, quis congue ipsum suscipit. Nam vitae suscipit erat, id maximus mauris. Etiam sollicitudin nunc justo, elementum porta elit dapibus id. Nullam nibh elit, fringilla eu nulla vitae, tincidunt posuere ex. Morbi congue elit id ligula accumsan blandit. Integer cursus vitae neque at sodales. Aenean quis ante magna. Mauris accumsan commodo purus, ac bibendum erat tempus quis. Mauris facilisis volutpat tellus, id volutpat lectus feugiat nec. <a href="https://www.flickr.com/"><img src="./photo2.jpg" align="bottom" width="400" height="265" border="2"></a> +</p> + + <p>[<stong>NH</strong><sub>4</sub>]<sup>+</sup></p> +<p> Page Composée par <cite>moi-même</cite>.<br/> +<p> +Vous pouvez m'écrire à cette adresse.</p> +<h6>©2015</h6> +</body></html> diff --git a/sem_3/SiteWeb/tp1/table.html b/sem_3/SiteWeb/tp1/table.html new file mode 100644 index 0000000..da726d2 --- /dev/null +++ b/sem_3/SiteWeb/tp1/table.html @@ -0,0 +1,49 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +</head> +<body> + + +<table bgcolor="wheat" bordercolor="#494949" border="3" align="center"> +<tr> +<th colspan="2" rowspan="3"> </th> +</tr> + +<tr> +<th colspan="2">Preferences</th> +</tr> +<tr> +<th> Kumquats frais </th> +<th> Kumquats au sirop </th> +</tr> +<tr> +<th rowspan="5" > Sexe </th> </tr> +<tr> +<td> Hommes de moins de 18 ans</td> +<td>45% </td> +<td> 55%</td> +</tr> + +<tr> +<td> Hommes de plus de 18 ans</td> +<td>51% </td> +<td>49% </td> +</tr> + +<tr> +<td>Femmes de moins de 18 ans </td> +<td>56% </td> +<td>44% </td> +</tr> + +<tr> +<td> Femmes de plus de 18 ans</td> +<td>63% </td> +<td> 37%</td> +</tr> + + +</table> + +</body> diff --git a/sem_3/SiteWeb/tp2/ImageCassoulet.jpg b/sem_3/SiteWeb/tp2/ImageCassoulet.jpg Binary files differnew file mode 100644 index 0000000..5dcc385 --- /dev/null +++ b/sem_3/SiteWeb/tp2/ImageCassoulet.jpg diff --git a/sem_3/SiteWeb/tp2/Thumbs.db b/sem_3/SiteWeb/tp2/Thumbs.db Binary files differnew file mode 100644 index 0000000..3088411 --- /dev/null +++ b/sem_3/SiteWeb/tp2/Thumbs.db diff --git a/sem_3/SiteWeb/tp2/base.css b/sem_3/SiteWeb/tp2/base.css new file mode 100644 index 0000000..dbfc7f4 --- /dev/null +++ b/sem_3/SiteWeb/tp2/base.css @@ -0,0 +1,21 @@ +body { + background-color:dimgray; +} +div.div1 { + background-color: #FF0000; + padding: 3px 5px 3px 5px; +} +div.div2 { + background-color: #00FF00; + padding: 3px 5px 3px 5px; +} +div.div3 { + background-color: #0000FF; + padding: 3px 5px 3px 5px; + border-style:solid; + border-width:2px; +} +div.div4 { + background-color: #007777; + padding: 3px 5px 3px 5px; +} diff --git a/sem_3/SiteWeb/tp2/base.html b/sem_3/SiteWeb/tp2/base.html new file mode 100644 index 0000000..9c49eff --- /dev/null +++ b/sem_3/SiteWeb/tp2/base.html @@ -0,0 +1,84 @@ +<html> + <head> + <link rel=stylesheet href=./base.css type=text/css> + </head> + <body> +<div class="div1"><p> + I <br> + Sed ut perspiciatis unde omnis iste natus error sit voluptatem +accusantium doloremque laudantium, +totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et +quasi architecto beatae vitae dicta sunt explicabo. + Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut +fugit, sed quia consequuntur magni dolores +eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, +qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, + sed quia non numquam eius modi tempora incidunt ut labore et dolore +magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, +quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi +ut aliquid ex ea commodi consequatur? Quis autem vel eum iure + reprehenderit qui in ea voluptate velit esse quam nihil molestiae +consequatur, vel illum qui dolorem eum +fugiat quo voluptas nulla pariatur?</p> +</div> + + +<div class="div2"><p> + II <br> + Sed ut perspiciatis unde omnis iste natus error sit voluptatem +accusantium doloremque laudantium, +totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et +quasi architecto beatae vitae dicta sunt explicabo. + Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut +fugit, sed quia consequuntur magni dolores +eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, +qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, + sed quia non numquam eius modi tempora incidunt ut labore et dolore +magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, +quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi +ut aliquid ex ea commodi consequatur? Quis autem vel eum iure + reprehenderit qui in ea voluptate velit esse quam nihil molestiae +consequatur, vel illum qui dolorem eum +fugiat quo voluptas nulla pariatur?</p> +</div> + +<div class="div3"><p> + III<br> + Sed ut perspiciatis unde omnis iste natus error sit voluptatem +accusantium doloremque laudantium, +totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et +quasi architecto beatae vitae dicta sunt explicabo. + Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut +fugit, sed quia consequuntur magni dolores +eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, +qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, + sed quia non numquam eius modi tempora incidunt ut labore et dolore +magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, +quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi +ut aliquid ex ea commodi consequatur? Quis autem vel eum iure + reprehenderit qui in ea voluptate velit esse quam nihil molestiae +consequatur, vel illum qui dolorem eum +fugiat quo voluptas nulla pariatur?</p> +</div> + +<div class="div4"><p> + IV<br> + Sed ut perspiciatis unde omnis iste natus error sit voluptatem +accusantium doloremque laudantium, +totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et +quasi architecto beatae vitae dicta sunt explicabo. + Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut +fugit, sed quia consequuntur magni dolores +eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, +qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, + sed quia non numquam eius modi tempora incidunt ut labore et dolore +magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, +quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi +ut aliquid ex ea commodi consequatur? Quis autem vel eum iure + reprehenderit qui in ea voluptate velit esse quam nihil molestiae +consequatur, vel illum qui dolorem eum +fugiat quo voluptas nulla pariatur?</p> +</div> + +</body> +</html> diff --git a/sem_3/SiteWeb/tp2/cassoulet.css b/sem_3/SiteWeb/tp2/cassoulet.css new file mode 100644 index 0000000..1c9c1a6 --- /dev/null +++ b/sem_3/SiteWeb/tp2/cassoulet.css @@ -0,0 +1,35 @@ +body { + background-color: #d3d3d3; +} + +ul { + background-color: #f5deb4; +} + +img { + float:right; +} + +table { + background-color: #ffa301; + margin-left: 33%; +} + +table tr th { + background-color: #fffe00; +} + +table caption { + background-color: #ffa301; +} + +li a { + color: darkgreen; +} + +p.note { + background-color: yellow; + margin-left:60px; + margin-right:60px; + font-size:x-small; +} diff --git a/sem_3/SiteWeb/tp2/cassoulet.html b/sem_3/SiteWeb/tp2/cassoulet.html new file mode 100644 index 0000000..821b788 --- /dev/null +++ b/sem_3/SiteWeb/tp2/cassoulet.html @@ -0,0 +1,84 @@ + +<HTML> +<Head> +<link rel=stylesheet href="./cassoulet.css" type=text/css> +</Head> +<body> + +<p> + + + + <h2>Cassoulet de Castelnaudary</h2> + +Pour 8 personnes - temps de cuisson 4h + + +<ul> + <li>800 g de haricots <a href="http://www.lingotdunord.com">lingots <a> ou mieux, de <a href="http://www.haricot-tarbais.com/">haricots tarbais</a>. + <li>800 g d'échine de porc + <li> 8 tranches de poitrine de porc + <li>200 g de couennes fraîches + <li>1 saucisson à l'ail + <li>2 cuillères de soupe de saindoux + <li>2 jarrets de porc salés + <li>250 g de tomates + <li>3 oignons piqués de clous de girofle + <li>200 g de carottes + <li>1 bouquet garni + <li>poivre concassé +</ul> +</p> + +<p> +<img src="cassoulet.jpg"> +Dans grand pot faire revenir avec du saindoux les tomates et la +poitrine de porc coupées en dés ainsi que les carottes +émincées. Déposer les haricots sur le roux + (tous les éléments au-dessus) dans le même pot, couvrir avec deux + litres d'eau, ajouter le bouquet garni, + l'ail, les oignons, les couennes, les jarrets dessalés et la + viande. Laisser mijoter deux heures à feu doux. + </p> + + <p> +Verser le tout dans une "cassole*", +ou un plat en terre creux et profond. Repartir la viande et adjoindre +le saucisson à l'ai coupé en tranches épaisses. +</p> + +<p> +Poser le plat dans un four très doux. Quand il est recouverte d'une + croûte dorée, appuyer + avec une spatule pour qu'elle s'enfonce dans les haricots + (recommencer six fois pendant + tout le cuisson). Cuire au four pour au moins deux heures. Cette + longue et minutieuse + préparation est essentielle pour la réussite d'un excellent + cassoulet. + </p> + + <p class="note"> + *Une "cassole" est un pot en terre d' <a href="http://www.issel.fr">Issel<a> dans laquelle on peut + mijoter et dorer. C'est l'origine du terme cassoulet. + +</p> + +</p> + +<table border> +<caption align=bottom> +L'apport nutritionnel du cassoulet pour 100g</caption> +<tr> +<th>Glucides</th> +<th>Lipides</th> +<th>Protides</th> +<tr> +<tr> +<td>45g</td> +<td>30g</td> +<td>25g</td> +<tr> +</table> +</body> +</HTML> diff --git a/sem_3/SiteWeb/tp2/cassoulet.jpg b/sem_3/SiteWeb/tp2/cassoulet.jpg Binary files differnew file mode 100644 index 0000000..f8a312d --- /dev/null +++ b/sem_3/SiteWeb/tp2/cassoulet.jpg diff --git a/sem_3/SiteWeb/tp2/index.html b/sem_3/SiteWeb/tp2/index.html new file mode 100644 index 0000000..3f1c656 --- /dev/null +++ b/sem_3/SiteWeb/tp2/index.html @@ -0,0 +1,65 @@ +<!DOCTYPE html>
+<html lang="fr">
+<head>
+ <meta charset="utf-8">
+ <title>Gaspard Coulet</title>
+ <link rel="stylesheet" href="../style.css">
+</head>
+<body>
+ <h1 id="titre"> TP2</h1>
+ <div class="Cadre">
+ <a class="lientp2" href="../index.html"><img class="image" alt="Image de l'acceuil" src="../photo.png">Acceuil</a>
+ <a class="lientp2" href="./base.html"target = "_blank"><img class="image" alt="Image du premer site web realisé en TP2" src="./photobase.png">Site Base</a>
+ <a class="lientp2" href="./cassoulet.html"target = "_blank"><img class="image" src="../photo2.png" alt="Image du second site web realisé en TP2">Site Cassoulet</a>
+ </div>
+ <div class="Cadre">
+ <h2> Notes et réponses aux questions :</h2><p>
+ Par défaut, une div html occupe de l'espace en fonction de son contenu, en l'occurence, la largeur est de
+ 100% de la page, et la hauteur est relative au nombre de ligne.</p><p>
+
+ Par défaut il n'y a pas de marge! Le décallage visible est du au padding du conteneur parent : ici body
+ qui lui a un padding par defaut de 8px, d'ailleurs, la notion de "par défaut" est absurde car elle dépend
+ du navigateur utilisé.</p><p>
+
+ On remarque que la largeur d'une bordure s'additionne avec le padding de la division.
+ </p><p>
+ En placant le texte contenu dans les div dans des balises p, on remarque qu'une marge se créée au dessus
+ et en dessous du texte, on peut même préciser que cette derniére fait 16 px.
+ </p><p>
+ Concernant la durée de vie des support de stockage, il apparait que le support le plus fiable est
+ le stockage flash.</p><p>
+
+ Parmis la liste de format fourni, seul le .jpg est un format compressé.
+
+ Parmis les formats d'archivage par defaut sur les sessions de la fac, les suivants permettent le verouillage :
+ .cbz; .ear; .war; .zip;
+ Ces 4 formats semblent permettre de protéger aussi la liste des fichiers.
+
+ La division en multiples petits fichiers peut permettre une plus grande sécurité lors des transfert par le reseau
+ ( une instabilitée du reseau risquant de couper le transfert, il est preferable de le faire morceau par
+ morceau, pour ne pas avoir à tout recommencer.
+ </p><p>
+ SAUVEGARDE
+ Sauvergarde incrementale :
+ "Méthode de backup se basant sur une sauvegarde complète, elle ne sert à sauvegarder que les fichiers modifiés depuis la dernière sauvegarde. Une sauvegarde incrémentielle copie donc uniquement les fichiers modifiés depuis la dernière sauvegarde complète ou incrémentielle et conserve les différentes versions d'un fichier.
+ Dès modification du ou des fichiers, l'attribut "archive" est positionné, devient "actif". C'est de cette façon que la sauvegarde incrémentale reconnait les fichiers modifiés pour les sauvegarder en réinitialisant du même coup cet attribut.
+ . Avantage : Comme une sauvegarde incrémentielle ne sauvegarde que les fichiers modifiés, elle constitue une protection rapide contre la perte de données. Elle nécessite également moins de ressources de stockage.
+ .Inconvénient : Chaque sauvegarde incrémentielle (entre deux sauvegardes complètes) doit être conservée car chacune d'elles se « construit » à partir de la précédente."
+ (<a href="http://www.infonitec.com/definition-informatique-telecom/definition-informatique-telecom.php?id=478"> reference</a> )
+ </p><p>
+ Synchronisation de supports : visiblement inexistant de google.
+ </p><p>
+ Gestion de version ( on est en france, s'il vous plait) :
+ "Lorsque vous travaillez sur un projet de code, vous allez régulièrement y apporter des modifications, et par moments ces modifications vont provoquer des bugs. Lorsque vous revenez sur votre projet après quelques jours ou même quelques heures, il peut être difficile de vous souvenir des dernières modifications que vous avez effectuées et de retrouver vos repères dans votre code.
+ Avec un logiciel de versioning comme Git, vous pouvez garder la trace de toutes les modifications faites sur votre code pour pouvoir vous y retrouver à tout moment. À chaque fois que vous faites une série de modifications (créer un fichier, supprimer un fichier, modifier un texte dans un fichier, etc.), vous allez pouvoir enregistrer ces modifs dans un commit."
+ ( <a href="http://openclassrooms.com">reference</a> )
+ </p><p>
+ Logiciel de sauvegarde incrémentielle : ex : Bacula.
+ Logiciel de gestion de version : Git.
+ </p><p>
+ Exemple de piratage d'information récent : <a href="https://techcrunch.com/2017/10/10/equifax-hack-included-nearly-11-million-us-drivers-licenses/"> ici</a>
+ </p>
+ </div>
+ <footer> <p> Par : Gaspard Coulet</p><p> Contact : <a href="mailto:gaspard.coulet@etu.umontpellier.fr"> gaspard.coulet@etu.umontpellier.fr</p></footer>
+ </body>
+ </html>
diff --git a/sem_3/SiteWeb/tp2/photobase.png b/sem_3/SiteWeb/tp2/photobase.png Binary files differnew file mode 100644 index 0000000..6ff1cfa --- /dev/null +++ b/sem_3/SiteWeb/tp2/photobase.png diff --git a/sem_3/SiteWeb/tp3/index.html b/sem_3/SiteWeb/tp3/index.html new file mode 100644 index 0000000..219adb4 --- /dev/null +++ b/sem_3/SiteWeb/tp3/index.html @@ -0,0 +1,25 @@ +<!DOCTYPE html>
+<html lang="fr">
+<head>
+ <meta charset="utf-8">
+ <title>Gaspard Coulet</title>
+ <link rel="stylesheet" href="../style.css">
+</head>
+<body>
+ <h1 id="titre"> TP3</h1>
+ <div class="Cadre">
+ <a class="lientp3" href="../index.html"><img class="image" alt="Image de l'acceuil" src="../photo.png">Acceuil</a>
+ <a class="lientp3" href="./texte.tar"><img class="image" alt="Images d'un fichier traitement de texte" src="../photo3.png">Télécharger les odt</a>
+ </div>
+ <div class="Cadre">
+ <h2> Notes et réponses aux questions : </h2>
+ <p> La touche Inser permet de basculer entre les modes "Insert" et "Overwrite", en Insert, on intercalle un caractere entre deux autres, là ou le mode Overwrite réécrit par dessus un caractère existant.</p>
+ <p> Le retour à la ligne via la touche "enter" simple créée un nouveau paragraphe, tandis que la combinaison "shift+enter" se contente de revenir a la ligne.</p>
+ <p> Un espace insécable entre 2 mots s'assure que le logiciel considère ces deux mots comme un seul, qui ne peut être separé par un retour a la ligne, par exemple.</p>
+ <p> Pour ne pas avoir un "canichene", il faut cocher l'option "mots entiers uniquement"</p>
+ <p> "respecter la casse" signifie respecter le 'taille' ( majuscule, minuscule) des lettres</p>
+ <p> Ancrer une image comme caractère sert à l'intégrer dans le texte comme un caractère</p>
+ </div>
+ <footer> <p> Par : Gaspard Coulet</p><p> Contact : <a href="mailto:gaspard.coulet@etu.umontpellier.fr"> gaspard.coulet@etu.umontpellier.fr</p></footer>
+ </body>
+ </html>
diff --git a/sem_3/SiteWeb/tp3/texte.tar b/sem_3/SiteWeb/tp3/texte.tar Binary files differnew file mode 100644 index 0000000..93630e3 --- /dev/null +++ b/sem_3/SiteWeb/tp3/texte.tar diff --git a/sem_3/SiteWeb/tp4/calc.tar b/sem_3/SiteWeb/tp4/calc.tar Binary files differnew file mode 100644 index 0000000..82117dd --- /dev/null +++ b/sem_3/SiteWeb/tp4/calc.tar diff --git a/sem_3/SiteWeb/tp4/index.html b/sem_3/SiteWeb/tp4/index.html new file mode 100644 index 0000000..c5f1b8d --- /dev/null +++ b/sem_3/SiteWeb/tp4/index.html @@ -0,0 +1,17 @@ +<!DOCTYPE html>
+<html lang="fr">
+<head>
+ <meta charset="utf-8">
+ <title>Gaspard Coulet</title>
+ <link rel="stylesheet" href="../style.css">
+</head>
+<body>
+ <h1 id="titre"> TP4</h1>
+ <div class="Cadre">
+ <a class="lientp4" href="../index.html"><img class="image" alt="Image de l'acceuil" src="../photo.png">Acceuil</a>
+ <a class="lientp4" href="./calc.tar"><img class="image" alt="Images d'un des classeurs réalisé" src="../photo4.png">Télécharger les ods</a>
+ </div>
+ <div class="Cadre"></div>
+ <footer> <p> Par : Gaspard Coulet</p><p> Contact : <a href="mailto:gaspard.coulet@etu.umontpellier.fr"> gaspard.coulet@etu.umontpellier.fr</p></footer>
+ </body>
+ </html>
diff --git a/sem_3/SiteWeb/tp5/exo1.odp b/sem_3/SiteWeb/tp5/exo1.odp Binary files differnew file mode 100644 index 0000000..daa852a --- /dev/null +++ b/sem_3/SiteWeb/tp5/exo1.odp diff --git a/sem_3/SiteWeb/tp5/index.html b/sem_3/SiteWeb/tp5/index.html new file mode 100644 index 0000000..6f22266 --- /dev/null +++ b/sem_3/SiteWeb/tp5/index.html @@ -0,0 +1,21 @@ +<!DOCTYPE html>
+<html lang="fr">
+<head>
+ <meta charset="utf-8">
+ <title>Gaspard Coulet</title>
+ <link rel="stylesheet" href="../style.css">
+</head>
+<body>
+ <h1 id="titre"> TP5</h1>
+ <div class="Cadre">
+ <a class="lientp5" href="../index.html"><img class="image" alt="Image de l'acceuil" src="../photo.png">Acceuil</a>
+ <a class="lientp5" href="./exo1.odp"><img class="image" alt="Image du diapo canard" src="../photo5.png">Télécharger l'odp</a>
+ <a class="lientp5" href="./gcoulet.odp"><img class="image" alt="Image du diapo perso à realiser" src="./photo.jpg">Télécharger l'odp</a>
+ </div>
+ <div class="Cadre"><p>Lorsque l'image est inserée en tant que lien, elle n'est pas copiée, on accede directement a
+ l'image sur le disque, dans ces conditions si l'image vient a changer de nom,
+ ou qu'un des dossiers parents de l'image change de nom, le lien est rompu.
+ </p></div>
+ <footer> <p> Par : Gaspard Coulet</p><p> Contact : <a href="mailto:gaspard.coulet@etu.umontpellier.fr"> gaspard.coulet@etu.umontpellier.fr</p></footer>
+ </body>
+ </html>
diff --git a/sem_3/algo/TP3/FichiersTP3.tgz b/sem_3/algo/TP3/FichiersTP3.tgz Binary files differnew file mode 100644 index 0000000..2986ae0 --- /dev/null +++ b/sem_3/algo/TP3/FichiersTP3.tgz diff --git a/sem_3/algo/TP3/enonceTP3.pdf b/sem_3/algo/TP3/enonceTP3.pdf Binary files differnew file mode 100644 index 0000000..887d4cb --- /dev/null +++ b/sem_3/algo/TP3/enonceTP3.pdf diff --git a/sem_3/algo/TP3/fichierTP3.cpp b/sem_3/algo/TP3/fichierTP3.cpp new file mode 100644 index 0000000..1b804ed --- /dev/null +++ b/sem_3/algo/TP3/fichierTP3.cpp @@ -0,0 +1,127 @@ +#include <iostream> +#include <fstream> +#include <string> +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include "progListeSC.h" +#include "fichierTP3.h" +using namespace std; + + + +bool estTrieeLSC(ListeSC L){ + // Res : Renvoie true si L est une ListeSC tri�e, false sinon + + if (estVideLSC(L) || estVideLSC(L->succ)) + return true; + else + return (L->info < (L->succ)->info) && estTrieeLSC(L->succ); +} + +bool estListeIntervalle(ListeSC L){ + // Res : renvoie true si L est une Liste intervalle, renvoie false sinon + // A COMPLETER + while ( L->succ != NULL) { + if (L->succ->info - L->info != 1) return false; + L=L->succ; + } + return true; +} + +ListeSC consListeIntervalle1(int l, int p){ + // Donn�e : l>0 + // Res : renvoie une liste intervalle de longueur l et dont le premier �l�ment a pour valeur p + // Complexit� : Complexité dans le pire cas : O(N^2) ( boucle for + complexité de base de insererFinLC) + assert(l>0); + + int i; ListeSC L; + L=NULL; + for(i=0;i<l;i++) + insererFinLSC(L,p+i); + return L; +} + +ListeSC consListeIntervalle2(int l, int p){ + // Donn�e : l>0 + // Res : renvoie une liste intervalle de longueur l et dont le premier �l�ment a pour valeur p + // Complexit� : O(N) + // Version iterative + p=p+l-1 ; //valeur du dernier element + ListeSC L = NULL; + while ( l>0) { + L=creerLSC(p, L); + p--; + l--; + } + return L; +} + +ListeSC consListeIntervalle3(int l, int p){ + // Donn�e : l>0 + // Res : renvoie une liste intervalle de longueur l et dont le premier �l�ment a pour valeur p + // Complexit� : O(N-1) + // Version r�cursive + ListeSC L=NULL; + if ( l == 0) return L; + else { + L = creerLSC(p,consListeIntervalle3(l-1,p+1)); + return L; + } +} + +void transfListeIntervalle(ListeSC L){ + // Donn�e : L est une liste tri�e non vide + // Res : modifie L en y inserant des �l�ments de sorte qu'elle soit une Liste Intervalle + // Complexit� : ???? + while ( L->succ != NULL) { + if (L->succ->info - L->info != 1) { + insererApresLSC(L,L,L->info+1); + } + L=L->succ; + } + return; +} + +ListeSC intersectionListesIntervalles(ListeSC l1, ListeSC l2){ + // Donn�e : l1 et l2 2 listes intervalles + // Res : Renvoie l'intersection de l1 et l2; les �l�ments de la liste r�sultat sont recopi�s + // Complexit� : ordre O(N) une premiere partie au moins inferieure a la somme + // de la longueur des listes, plus un appel lineaire a consListeIntervalle2 + assert(estListeIntervalle(l1)); + assert(estListeIntervalle(l2)); + while (l1 != NULL && l2 != NULL && l1->info != l2->info){ + if (l1->info<l2->info){ + l1= l1->succ; + } + else { + l2=l2->succ; + } + } + int p= l1->info; + int l =0; + while ( l1 != NULL && l2 != NULL && l1->info == l2->info){ + l1=l1->succ; + l2=l2->succ; + l++; + } + return consListeIntervalle2(l,p); +} + +void plusLgSsLiInterv(ListeSC &L){ + // Donn�e : L liste + // Res : L est modifiee, elle est la plus longue sous-liste intervalle de la liste en entr�e + // Complexit� : ???? + // ListeSC ret = L; + // ListeSC ancien = NULL; + // int lenght = 0; + // while ( ret->succ != NULL){ + // if (ret->succ->info - ret->info != 1){ + // lenght=0; + // ret=ret->succ; + // } + // else { + // ancien + // } + // } +} diff --git a/sem_3/algo/TP3/fichierTP3.h b/sem_3/algo/TP3/fichierTP3.h new file mode 100644 index 0000000..17cf091 --- /dev/null +++ b/sem_3/algo/TP3/fichierTP3.h @@ -0,0 +1,43 @@ + +#ifndef FicTP3_H +#define FicTP3_H + + +bool estTrieeLSC(ListeSC L); + // Res : Renvoie true si L est une ListeSC triée, false sinon + +bool estListeIntervalle(ListeSC L); + // Res : renvoie true si L est une Liste intervalle, renvoie false sinon + +ListeSC consListeIntervalle1(int l, int p); + // Donnée : l>0 + // Res : renvoie une liste intervalle de longueur l et dont le premier élément a pour valeur p + +ListeSC consListeIntervalle2(int l, int p); + // Donnée : l>0 + // Res : renvoie une liste intervalle de longueur l et dont le premier élément a pour valeur p + +ListeSC consListeIntervalle3(int l, int p); + // Donnée : l>0 + // Res : renvoie une liste intervalle de longueur l et dont le premier élément a pour valeur p + + +void transfListeIntervalle(ListeSC L); + // Donnée : L est une liste triée non vide + // Res : modifie L en y inserant des éléments de sorte qu'elle soit une Liste Intervalle + +ListeSC intersectionListesIntervalles(ListeSC l1, ListeSC l2); + // Donnée : l1 et l2 2 listes intervalles + // Res : Renvoie l'intersection de l1 et l2; les éléments de la liste résultat sont recopiés + + +void plusLgSsLiInterv(ListeSC &L); + // Donnée : L liste + // Res : L est modifiee, elle est la lus longue sous-liste intervalle de la liste en entrée + + +#endif + + + + diff --git a/sem_3/algo/TP3/mainTP3.cpp b/sem_3/algo/TP3/mainTP3.cpp new file mode 100644 index 0000000..a0fb341 --- /dev/null +++ b/sem_3/algo/TP3/mainTP3.cpp @@ -0,0 +1,84 @@ +#include <iostream> +#include <fstream> +#include <string> +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include "progListeSC.h" +#include "fichierTP3.h" + +using namespace std; + + +int main(int argc, char *argv[]){ + ListeSC l1,l2,l3; + int q, lg, prem; + clock_t t1,t2,t3, t4; + + cout << "Numero de la question traitee (1/2/3/4/5/6) ? "; + cin >> q ; + switch (q){ + case 1 : + l1=lireLSC(); + if (estListeIntervalle(l1)) + cout << "Cette liste est une liste intervalle \n"; + else + cout << "Cette liste n'est pas une liste intervalle \n"; + break; + + case 2 : + cout << "Donnez 2 entiers strictement positifs (longueur et premier element de la liste intervalle) : "; + cin >> lg >> prem; + l1=consListeIntervalle1(lg,prem); + afficherLSC(l1); + l2=consListeIntervalle2(lg,prem); + afficherLSC(l2); + l3=consListeIntervalle3(lg,prem); + afficherLSC(l3); + break; + case 3 : + cout << "Donnez 2 entiers strictement positifs (longueur et premier element de la liste intervalle) : "; + cin >> lg >> prem; + t1=clock(); + l1=consListeIntervalle1(lg,prem); + t2=clock(); + l2=consListeIntervalle2(lg,prem); + t3=clock(); + l3=consListeIntervalle3(lg,prem); + t4=clock(); + + cout << " Construction d'une Liste de taille " << lg + << "\n version 1 " <<(double) (t2-t1)/CLOCKS_PER_SEC + << " sec\n version 2 " <<(double) (t3-t2)/CLOCKS_PER_SEC + << " sec\n version 3 "<<(double) (t4-t3)/CLOCKS_PER_SEC<< " sec\n"; + break; + case 4 : // Transformation d'une liste triee en liste Intervalle + cout << "Entrez une Liste Triee : "; + l1=lireLSC(); + transfListeIntervalle(l1); + cout << "Liste Intervalle construite "; + afficherLSC(l1); + break; + case 5 : // intersection de 2 listes intervalle + cout << "Liste intervalle : "; + l1=lireLSC(); + cout << "Liste intervalle : "; + l2=lireLSC(); + l3=intersectionListesIntervalles(l1,l2); + cout << "Intersection : \n"; + afficherLSC(l3); + break; + case 6 : + cout << "Entrez une Liste : "; + l1=lireLSC(); + plusLgSsLiInterv(l1); + cout << "Plus longue sousListe Intervalle : "; + afficherLSC(l1); + } + return 0; +} + + + + + diff --git a/sem_3/algo/TP3/progListeSC.cpp b/sem_3/algo/TP3/progListeSC.cpp new file mode 100644 index 0000000..40efb3e --- /dev/null +++ b/sem_3/algo/TP3/progListeSC.cpp @@ -0,0 +1,105 @@ +// progListeSC.c +#include <iostream> +#include <fstream> +#include <assert.h> +#include <stdlib.h> +#include <stdio.h> +#include "progListeSC.h" + +using namespace std; + + +int estVideLSC(ListeSC l) +{ return (l==NULL);} + +ListeSC creerLSC(int val, ListeSC succ){ + ListeSC l = new CelluleSC; + l->info=val; + l->succ=succ; + return l;} + +void insererDebutLSC(ListeSC &p, int val){ + p=creerLSC(val,p); + return;} + +void insererApresLSC(ListeSC &l, ListeSC p, int val){ + assert((l)!=NULL); assert(p!=NULL); + (p->succ)=creerLSC(val,(p->succ)); + return;} + +void insererFinLSC(ListeSC &p, int val){ + if (p==NULL) + p=creerLSC(val,NULL); + else + insererFinLSC(p->succ,val); + return; +} + +ListeSC predecesseurLSC(ListeSC L, ListeSC P){ + assert(L!=NULL); + assert(P!=NULL); + + if (L->succ==P){return L;} + else {return predecesseurLSC(L->succ,P);} +} + +void supprimerLSC(ListeSC &L, ListeSC P){ + assert(L!=NULL); + assert(P!=NULL); + + if (L==P){L = L->succ;} + else { + predecesseurLSC(L,P)->succ = P->succ; + } + delete P; + return;} + +void supprimerDebutLSC(ListeSC &L){ + ListeSC P; + assert(L!=NULL); + + P=L; + L=L->succ; + delete P; + + return;} + + +void supprimerFinLSC(ListeSC &L){ + assert(L!=NULL); + + if (L->succ==NULL){ + delete L; + L=NULL;} + else { + ListeSC P=L,Q; + while ((P->succ)->succ!=NULL){ + P=P->succ;} + Q=P->succ; + P->succ=NULL; + delete Q;} + return;} + + + +void afficherLSC(ListeSC l){ + cout << "ListeSC : "; + while (! estVideLSC(l)){ + cout << l->info << " "; + l=l->succ;} + cout << endl; + return;} + +ListeSC lireLSC(){ + ListeSC l; + int i; + cout << "Entrez les éléments d'une liste d'entiers (0 pour finir)\n"; + l=NULL; + cin >> i; + while (i!=0) { + insererFinLSC(l,i); + cin >> i; + } + return l; +} + diff --git a/sem_3/algo/TP3/progListeSC.h b/sem_3/algo/TP3/progListeSC.h new file mode 100644 index 0000000..e35deed --- /dev/null +++ b/sem_3/algo/TP3/progListeSC.h @@ -0,0 +1,56 @@ + +//* ListeSC.h * +// Implantation du type Liste d'entiers Simplement Chainée + +#ifndef LISTESC_H +#define LISTESC_H + +typedef struct cellule { + int info; + struct cellule *succ;} CelluleSC; + +typedef CelluleSC *ListeSC; + + +// Res : renvoie 1 si L est la liste vide, renvoie 1 sinon +int estVideLSC(ListeSC L ); + +// Res : renvoie une ListeSC dont le premier élément est e et la suite de la liste L +ListeSC creerLSC(int e, ListeSC L); + +// Res : modifie la ListeSC L en y insérant en première place l'élément e +void insererDebutLSC(ListeSC &L, int e); + +// Donnée : L est une ListeSC non vide, P l'adresse d'un élément de L, e un entier +// Res : insère dans la liste L après l'élément d'adresse P 1 élément de valeur e +void insererApresLSC(ListeSC &L, ListeSC P, int e); + +// Res : modifie la listeSC L en y insérant en dernière place l'élément e +void insererFinLSC(ListeSC &L, int e); + +// Donnée : L est une ListeSC non Vide ; +// P est un pointeur non vide vers une cellule de la liste L +// L != P +// Res : renvoie l'adresse de la cellule précédant dans L celle pointée pas P +ListeSC predecesseurLSC(ListeSC L, ListeSC P); + +// Donnée : L est une ListeSC non Vide ; +// P est un pointeur non vide vers une cellule de la liste L +// Res : modifie L en supprimant de L la cellule pointée pas P +void supprimerLSC(ListeSC &L, ListeSC P); + +// Donnée : L est une ListeSC non Vide ; +// Res : modifie L en supprimant son dernier élément +void supprimerFinLSC(ListeSC &L); + +// Donnée : L est une ListeSC non Vide ; +// Res : modifie L en supprimant son premier élément +void supprimerDebutLSC(ListeSC &L); + +// Res : affiche la liste L +void afficherLSC(ListeSC L); + +// Res : renvoie la ListeSC des éléments saisis au clavier +ListeSC lireLSC(); + +#endif //LISTESC_H diff --git a/sem_3/algo/TP3/tp3 b/sem_3/algo/TP3/tp3 Binary files differnew file mode 100644 index 0000000..527995d --- /dev/null +++ b/sem_3/algo/TP3/tp3 diff --git a/sem_3/algo/TP4/fichierTP4.cpp b/sem_3/algo/TP4/fichierTP4.cpp new file mode 100644 index 0000000..9b90ad7 --- /dev/null +++ b/sem_3/algo/TP4/fichierTP4.cpp @@ -0,0 +1,194 @@ +#include <iostream> +#include <sstream> +#include <fstream> +#include <string> +//#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include "progListeSC.h" +using namespace std; + +typedef struct noeud { + int info; + struct noeud *sag; + struct noeud *sad;} NoeudSC; +typedef NoeudSC *ArbreBin; + +ArbreBin creerArbreBin(int e, ArbreBin G, ArbreBin D){ + /* Res : renvoie une ArbreBin dont la racine vaut e, le sag G et le sad D */ + ArbreBin A = new NoeudSC; + A->info=e; A->sag=G; A->sad=D; + return A;} + +void codageABdot(ofst ream& fichier, ArbreBin A){ + if (A != NULL){ + fichier << (long) A << " [label=\"" << A->info << "\" ] ;\n"; + if (A->sag != NULL) { + fichier << (long)A << " -> " << (long)(A->sag) << " [color=\"red\",label=\"g\" ] ;\n"; + codageABdot(fichier,A->sag);} + if (A->sad != NULL) { + fichier << (long)A << " -> " << (long)(A->sad) << " [color=\"blue\",label=\"d\" ] ;\n"; + codageABdot(fichier,A->sad);} + } + return;} + + +void dessinerAB(ArbreBin A, const char * nomFic, string titre){ + ofstream f(nomFic); + if (!f.is_open()){ + cout << "Impossible d'ouvrir le fichier en �criture !" << endl; + } + else { + f<< "digraph G { label = \""<< titre << "\" \n"; + codageABdot(f,A); + f << "\n }\n" ; + f.close();} + return;} + + +/* A COMPLETER */ +int sommeNoeuds(ArbreBin A){ + /* renvoie la somme des etiquettes des noeuds de l arbre binaire A */ + /* A COMPLETER */ + return A == NULL ? 0: A->info+sommeNoeuds(A->sag)+sommeNoeuds(A->sad); +} + +int profMinFeuille(ArbreBin A){ + /* renvoie la profondeur minimum des feuilles de l'arbre A ; A est non vide */ + assert(A!=NULL); + /* A COMPLETER */ + return A==NULL ? 0: A->info + ( profMinFeuille(A->sag)<= profMinFeuille(A->sad)) ? profMinFeuille(A->sag):profMinFeuille(A->sad)); +} + +ListeSC parcoursInfixe(ArbreBin A){ + /* renvoie la liste composee des etiquettes des noeuds de l'arbre A ordonn�e + selon l'ordre infixe */ + /* A COMPLETER */ + return A==NULL ? NULL: concatLSC(concatLSC(parcoursInfixe((A->sag), A->info),A->sad)); +} + +void effeuiller(ArbreBin& A){ + /* modifie l'arbre A en supprimant ses feuilles */ + /* A COMPLETER */ + return;} + +void tailler(ArbreBin& A, int p){ + /* modifie l'arbre A, en supprimant ses noeuds de profondeur au moins p ; p est un entier positif ou nul */ + /* A COMPLETER */ + return;} + +void tronconner(ArbreBin& A){ + /* modifie l'arbre A, en supprimant les noeuds dont un seul sous-arbre est vide */ + /* A COMPLETER */ + return;} + +ArbreBin genereAB(int n){ + /* A COMPLETER */ + return NULL;} + + +bool estParfait(ArbreBin A){ + // V�rifie si A est un arbre binaire parfait + return true; +} + +/*****************************************************************************/ +/* */ +/* main */ +/* */ +/*****************************************************************************/ +int main(int argc, char *argv[]){ + int q,i; + ArbreBin A,B,C; + ostringstream stre; + ListeSC L; + string chaine; + A=creerArbreBin(8, + creerArbreBin(7, + creerArbreBin(4,NULL,NULL), + creerArbreBin(9,NULL,NULL)), + creerArbreBin(3,NULL,NULL)); + + B=creerArbreBin(8, + creerArbreBin(2, + creerArbreBin(4,NULL,NULL), + creerArbreBin(9, + NULL, + creerArbreBin(1, + NULL, + creerArbreBin(7, + creerArbreBin(11,NULL,NULL), + creerArbreBin(5, + NULL, + NULL))))), + creerArbreBin(3, + creerArbreBin(12, + creerArbreBin(6,NULL,NULL), + NULL), + creerArbreBin(9,NULL,NULL))); + C=NULL; + C= creerArbreBin(1,C,C); + cout << "Numero de la question traitee (1/2/3/4/5/6/7) ? "; + cin >> q; + switch (q){ + case 1 : + dessinerAB(A,"arbre.dot","Arbre Bin"); + cout << "Somme des noeuds de l'arbre :"<< sommeNoeuds(A) << endl; + cout << "Profondeur minimum des feuilles de l'arbre : " << profMinFeuille(A) << endl; + system("dotty arbre.dot"); + break; + case 2 : + dessinerAB(A,"arbre.dot","Arbre Bin"); + L=parcoursInfixe(A); + cout << "Liste des noeuds de l'arbre en ordre infixe : "; + afficherLSC(L); + system("dotty arbre.dot"); + break; + case 3 : + dessinerAB(B,"arbre.dot","Arbre Bin"); + system("dotty arbre.dot&"); + effeuiller(B); + dessinerAB(B,"arbre2.dot","Arbre Bin effeuille"); + system("dotty arbre2.dot"); + break; + case 4 : + dessinerAB(B,"arbre.dot","Arbre Bin"); + system("dotty arbre.dot&"); + cout << " Donner une profondeur (entier positif) :"; + cin >> i; + tailler(B,i); + stre << i; + chaine = stre.str(); + chaine = "Arbre Bin taille a la profondeur " + chaine; + dessinerAB(B,"arbre2.dot",chaine); + system("dotty arbre2.dot&"); + break; + case 5 : + cout << " Donner un entier positif :"; + cin >> i; + stre << i; + chaine = "Arbre Bin " + stre.str(); + dessinerAB(genereAB(i),"arbre.dot", "Arbre Bin " + stre.str()); + system("dotty arbre.dot&"); + break; + case 6 : + dessinerAB(B,"arbre.dot","Arbre Bin"); + system("dotty arbre.dot&"); + tronconner(B); + dessinerAB(B,"arbre2.dot","Arbre tronconne"); + system("dotty arbre2.dot&"); + break; + case 7 : + A=genereAB(7); + chaine= estParfait(A) ? "Arbre parfait" : "Arbre non parfait"; + dessinerAB(A,"arbre.dot",chaine); + system("dotty arbre.dot"); + + B=genereAB(8); + chaine= estParfait(B) ? "Arbre parfait" : "Arbre non parfait"; + dessinerAB(B,"arbre2.dot",chaine); + system("dotty arbre2.dot&"); + break; + } + return 0; +} diff --git a/sem_3/algo/TP4/progListeSC.cpp b/sem_3/algo/TP4/progListeSC.cpp new file mode 100644 index 0000000..0a88c29 --- /dev/null +++ b/sem_3/algo/TP4/progListeSC.cpp @@ -0,0 +1,114 @@ +/**************************** progListeSC.c **********************************/ + +#include <iostream> +#include <fstream> +#include <assert.h> +#include <stdlib.h> +#include <stdio.h> +#include "progListeSC.h" + +using namespace std; + + +bool estVideLSC(ListeSC l) +{ return (l==NULL);} + +ListeSC creerLSC(int val, ListeSC succ){ + ListeSC l = new CelluleSC; + l->info=val; + l->succ=succ; + return l;} + +void insererDebutLSC(ListeSC& p, int val){ + p=creerLSC(val,p); +} + +void insererApresLSC(ListeSC& l, ListeSC p, int val){ + assert((l)!=NULL); assert(p!=NULL); + (p->succ)=creerLSC(val,(p->succ)); +} + +void insererFinLSC(ListeSC& p, int val){ + if ((p)==NULL) + p=creerLSC(val,NULL); + else + insererFinLSC(p->succ,val); +} + +ListeSC predecesseurLSC(ListeSC L, ListeSC P){ + assert(L!=NULL); + assert(P!=NULL); + + if (L->succ==P){return L;} + else {return predecesseurLSC(L->succ,P);} +} + +void supprimerLSC(ListeSC& L, ListeSC P){ + assert(L!=NULL); + assert(P!=NULL); + + if (L==P){L=L->succ;} + else { + predecesseurLSC(L,P)->succ=P->succ; + } + delete(P); +} + +void supprimerDebutLSC(ListeSC& L){ + ListeSC P; + + assert(L!=NULL); + + + P=L; + L=L->succ; + delete(P); +} + + +void supprimerFinLSC(ListeSC& L){ + assert(L!=NULL); + + if (L->succ==NULL){ + delete(L); + L=NULL;} + else { + ListeSC P=L,Q; + while ((P->succ)->succ!=NULL){ + P=P->succ;} + Q=P->succ; + P->succ=NULL; + delete(Q);} +} + + + +void afficherLSC(ListeSC l){ + cout<< "ListeSC : "; + while (! estVideLSC(l)){ + cout << " " << l->info <<" "; + l=l->succ;} + cout << endl; +} + +ListeSC lireLSC(){ + ListeSC l; + int i; + cout << "Entrez les éléments d'une liste d'entiers (0 pour finir)\n"; + l=NULL; + cin >> i; + while (i!=0) { + insererFinLSC(l,i); + cin >>i ; + } + return l; +} + +ListeSC concatLSC(ListeSC L1, ListeSC L2){ + ListeSC P; + if (L1==NULL) return L2; + else { + P= L1; + while (P->succ != NULL) P=P->succ; + P->succ = L2; + return L1;}} diff --git a/sem_3/algo/TP4/progListeSC.h b/sem_3/algo/TP4/progListeSC.h new file mode 100644 index 0000000..f60d8f4 --- /dev/null +++ b/sem_3/algo/TP4/progListeSC.h @@ -0,0 +1,59 @@ + +/**************************** ListeSC.h **************************************/ +/* Implantation du type Liste d'entiers Simplement Chainée */ + +#ifndef LISTESC_H +#define LISTESC_H + +typedef struct cellule { + int info; + struct cellule *succ;} CelluleSC; + +typedef CelluleSC *ListeSC; + + +bool estVideLSC(ListeSC L ); +/* Res : renvoie 1 si L est la liste vide, renvoie 1 sinon */ + +ListeSC creerLSC(int e, ListeSC L); +/* Res : renvoie une ListeSC dont le premier élément est e et la suite de la liste L */ + +void insererDebutLSC(ListeSC & L, int e); +/* Res : modifie la ListeSC L en y insérant en premiere place l'élément e */ + +void insererApresLSC(ListeSC & L, ListeSC P, int e); +/* Donnée : L est une ListeSC non vide, P l'adresse d'un élément de L, e un entier */ +/* Res : insère dans la liste L après l'élément d'adresse P 1 élément de valeur e */ + +void insererFinLSC(ListeSC & L, int e); +/* Res : modifie la listeSC L en y insérant en dernière place l'élément e */ + +ListeSC predecesseurLSC(ListeSC L, ListeSC P); +/* Donnée : L est une ListeSC non Vide ; */ +/* P est un pointeur non vide vers une cellule de la liste L */ +/* L != P */ +/* Res : renvoie l'adresse de la cellule précédant dans L celle pointée pas P */ + +void supprimerLSC(ListeSC & L, ListeSC P); +/* Donnée : L est une ListeSC non Vide ; */ +/* P est un pointeur non vide vers une cellule de la liste L */ +/* Res : modifie L en supprimant de L la cellule pointée pas P */ + +void supprimerFinLSC(ListeSC & L); +/* Donnée : L est une ListeSC non Vide ; */ +/* Res : modifie L en supprimant son dernier élément */ + +void supprimerDebutLSC(ListeSC & L); +/* Donnée : L est une ListeSC non Vide ; */ +/* Res : modifie L en supprimant son premier élément */ + +void afficherLSC(ListeSC L); +/* Res : affiche la liste L */ + +ListeSC lireLSC(); +/* Res : renvoie la ListeSC des éléments saisis au clavier */ + +ListeSC concatLSC(ListeSC L1, ListeSC L2); +/* Res : renvoie la ListeSC, concaténation des listes L1 et L2, en modifiant le chaînage de L1*/ + +#endif /*LISTESC_H*/ diff --git a/sem_3/algo/TP4/tpIN301_4.pdf b/sem_3/algo/TP4/tpIN301_4.pdf Binary files differnew file mode 100644 index 0000000..fde8e51 --- /dev/null +++ b/sem_3/algo/TP4/tpIN301_4.pdf diff --git a/sem_3/algo/tp1-done/PROG_TP1/mainTP1.cpp b/sem_3/algo/tp1-done/PROG_TP1/mainTP1.cpp new file mode 100644 index 0000000..18d30ab --- /dev/null +++ b/sem_3/algo/tp1-done/PROG_TP1/mainTP1.cpp @@ -0,0 +1,65 @@ +#include <iostream> +#include <fstream> +#include <string> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include "outilsTab.h" + +using namespace std; + + +int main(int argc, char ** argv) +{ + int* Tab; + struct triplet res; + int sm, taille, q; + clock_t t1, t2; + + srand(time(NULL)); + printf("Numero de la question traitee (1/2/3/4) ? "); + scanf("%d",&q); + switch (q){ + case 1 : + taille=1000; + Tab=genTab(taille); + t1=clock(); sm=ssTabSomMax1(Tab,taille); t2=clock(); + cout << "\n Somme Max1 : " << sm << " tps : " << (double) (t2-t1)/ (double) CLOCKS_PER_SEC << endl; + t1=clock(); sm=ssTabSomMax2(Tab,taille); t2=clock(); + cout << "\n Somme Max2 : " << sm << " tps : " << (double) (t2-t1)/ (double) CLOCKS_PER_SEC << endl; + t1=clock(); sm=ssTabSomMax3(Tab,taille); t2=clock(); + cout << "\n Somme Max3 : " << sm << " tps : " << (double) (t2-t1)/ (double) CLOCKS_PER_SEC << endl; + t1=clock(); sm=ssTabSomMax4(Tab,taille); t2=clock(); + cout << "\n Somme Max4 : " << sm << " tps : " << (double) (t2-t1)/ (double) CLOCKS_PER_SEC << endl; + + break; + case 2 : + fichierTemps("sm1.dat", 1000, 100, ssTabSomMax1); + fichierTemps("sm2.dat", 1000, 100, ssTabSomMax2); + fichierTemps("sm3.dat", 1000, 100, ssTabSomMax3); + fichierTemps("sm4.dat", 1000, 100, ssTabSomMax4); + system("gnuplot trace1.gnu"); + fichierTemps("sm2.dat", 20000, 1000, ssTabSomMax2); + fichierTemps("sm3.dat", 20000, 1000, ssTabSomMax3); + fichierTemps("sm4.dat", 20000, 1000, ssTabSomMax4); + system("gnuplot trace2.gnu"); + fichierTemps("sm3.dat", 1000000, 100000, ssTabSomMax3); + fichierTemps("sm4.dat", 10000000, 1000000, ssTabSomMax4); + system("gnuplot trace3.gnu"); + break; + case 3 : + Tab=genTab(20); + afficheTab(Tab,20); + res=indSsTabSomMax(Tab,20); + cout << "\n somme Max : " << res.somMax << "\n debut souTab : " << res.deb << "\n fin SouTab : " << res.fin << endl; + break; + case 4 : + Tab=genTab(20); + afficheTab(Tab,20); + rangerElemNeg(Tab,20); + afficheTab(Tab,20); + break; + } + return 0; +} + diff --git a/sem_3/algo/tp1-done/PROG_TP1/outilsTab.cpp b/sem_3/algo/tp1-done/PROG_TP1/outilsTab.cpp new file mode 100644 index 0000000..6643b13 --- /dev/null +++ b/sem_3/algo/tp1-done/PROG_TP1/outilsTab.cpp @@ -0,0 +1,131 @@ +#include <iostream> +#include <fstream> + +#include <stdlib.h> // pour rand +#include <assert.h> +#include "outilsTab.h" +using namespace std; + +int* genTab(int n){ + int* t; int i; + t=new int[n]; + for (i=0;i<n;i++) t[i]=-100+rand()%200; + return t; +} + +void afficheTab(int* T, int taille){ + int i; + cout << "\n[ "; + for (i=0;i<taille;i++) cout << T[i] << " "; + cout << "]\n"; + } + +void fichierTemps(const char* nomFic, int tMaxTab, int pas, int (*f)(int*, int)){ + int taille; + int* Tab; + clock_t t1, t2; + ofstream fichier(nomFic,ios::out); + + if (fichier) + { + for (taille=pas; taille<=tMaxTab; taille=taille+pas){ + Tab=genTab(taille); + t1=clock(); + (*f)(Tab,taille); + t2=clock(); + fichier << taille <<" "<< (double)(t2-t1)/ CLOCKS_PER_SEC << endl; + } + fichier.close(); + } + else cerr << " Problème ouverture fichier"<< endl; + + return ; +} + +int ssTabSomMax1(int* T, int taille){ + int somMax, som, i, j, k; + somMax=0; + for (i=0;i<taille;i++){ + for (j=i; j<taille; j++){ + som=0; + for (k=i; k<=j; k++) { + som = som + T[k]; + } + if (som > somMax) somMax = som; + } + } + return somMax; +} + +int ssTabSomMax2(int* T, int taille){ + int somMax, som, i, j; + somMax=0; + for (i=0;i<taille;i++){ + som=0; + for (j=i; j<taille; j++){ + som = som + T[j]; + if (som > somMax) somMax = som; + } + } + return somMax; +} + +int sTSM3(int* T,int g,int d){ + int m, som, i, smgd, smdg, smm, smg, smd; + assert(g<=d); + if (g==d){ + if (T[g]>0) return T[g]; else return 0; + } + else { + m = (d+g)/2; + smg=sTSM3(T,g,m); + smd=sTSM3(T,m+1,d); + smgd=0; som=0; + for (i=m;i>=g;i--){ + som=som+T[i]; + if (som > smgd) smgd=som; + } + smdg=0; som=0; + for(i=m+1;i<=d;i++){ + som=som+T[i]; + if (som>smdg) smdg=som; + } + smm=smgd+smdg; + if ((smg>=smd) && (smg>=smm)) return smg; + else { + if (smd>=smm) return smd; + else return smm; + } + } +} + +int ssTabSomMax3(int* T, int taille){ + return sTSM3(T,0,taille-1); +} + +int ssTabSomMax4(int* T, int taille){ + int ancienplusgrand = 0; + int somme =0; + for (int i =0; i < taille; i ++) { + somme+=T[i]; + if (somme < 0 ){ + somme= 0; + } + ancienplusgrand= ancienplusgrand> somme ? ancienplusgrand : somme; + } + return ancienplusgrand; +} + +struct triplet indSsTabSomMax(int* T, int taille){ +/* A COMPLETER */ + struct triplet res; + res.somMax=0; res.deb=0; res.fin=0; + return res; +} + + +void rangerElemNeg(int* T,int taille){ +/* A COMPLETER */ + return; + +} diff --git a/sem_3/algo/tp1-done/PROG_TP1/outilsTab.h b/sem_3/algo/tp1-done/PROG_TP1/outilsTab.h new file mode 100644 index 0000000..9576c28 --- /dev/null +++ b/sem_3/algo/tp1-done/PROG_TP1/outilsTab.h @@ -0,0 +1,74 @@ +#ifndef OUTILSTAB_H_INCLUDED +#define OUTILSTAB_H_INCLUDED + +struct triplet { + int deb, fin, somMax;} ; + +int* genTab(int t); +// Renvoie un tableau de taille t, dont les éléments sont des entiers aléatoires compris entre -100 et 100 + + +void afficheTab(int* T, int t); +// Affiche les éléments de T, tableau d'entiers de taille t + + +void fichierTemps(const char* nomFic, int tMaxTab, int pasTaille, int (*fssTabSomMax)(int*, int)); +// Données nomFic une chaîne de caractères, tMaxTab et pasTaille 2 entiers positifs pasTaille < tMaxTab +// fssTabSomMax nom d'une fonction dont les données sont 1 tableau d'entiers et la taille de ce tableau et renvoyant 1 entier +// Resultat : crée un fichier de nom nomfic et pour chaque taille comprise entre pasTaille et tMaxTab (avec un pas de pasTaille), +// génère un tableau de cette taille +// execute la fonction ssTabSomMax sur ce tableau +// ajoute au fichier de nom nomfic la taille du tableau et le temps d'execution de ssTabSomMax + + +int ssTabSomMax1(int* Tab, int n); +/* + Données : Tab un tableau d'entiers de taille n + Resultat : renvoie la somme max des sous-tableaux de tab, algo de complexite O(n^3) +*/ + +int ssTabSomMax2(int*, int); + +/* + Données : Tab un tableau d'entiers de taille n + Resultat : renvoie la somme max des sous-tableaux de tab, algo de complexite O(n^2) +*/ + +int ssTabSomMax3(int* Tab, int n); +/* + Données : Tab un tableau d'entiers de taille n + Resultat : renvoie la somme max des sous-tableaux de tab, algo de complexite O(n log n) +*/ + +int ssTabSomMax4(int* Tab, int n); +/* + Données : Tab un tableau d'entiers de taille n + Resultat : renvoie la somme max des sous-tableaux de tab, algo de complexite O(n) + FONCTION A COMPLETER +*/ + +struct triplet indSsTabSomMax(int* Tab,int n); +/* + Données : Tab un tableau d'entiers de taille n + Resultat : renvoie une structure contenant + la somme max des sous-tableaux de tab, + l'indice de début d'un sous-tableau de somme max + l'indice de fin d'un sous-tableau de somme max + algo de complexite O(n) + FONCTION A COMPLETER + +*/ + + +void rangerElemNeg(int* Tab,int n); +/* + Données : Tab un tableau d'entiers de taille n + Resultat : modifie le tableau Tab de sorte que tous les éléments négatifs soient placés avant tous les éléments positifs + algo de complexite O(n) + FONCTION A COMPLETER + +*/ + + + +#endif /* OUTILSTAB_H_INCLUDED */ diff --git a/sem_3/algo/tp1-done/PROG_TP1/sm1.dat b/sem_3/algo/tp1-done/PROG_TP1/sm1.dat new file mode 100644 index 0000000..6fe54af --- /dev/null +++ b/sem_3/algo/tp1-done/PROG_TP1/sm1.dat @@ -0,0 +1,10 @@ +100 0 +200 0 +300 0.03125 +400 0.03125 +500 0.046875 +600 0.09375 +700 0.15625 +800 0.21875 +900 0.3125 +1000 0.4375 diff --git a/sem_3/algo/tp1-done/PROG_TP1/sm2.dat b/sem_3/algo/tp1-done/PROG_TP1/sm2.dat new file mode 100644 index 0000000..79cda5f --- /dev/null +++ b/sem_3/algo/tp1-done/PROG_TP1/sm2.dat @@ -0,0 +1,7 @@ +1000 0 +2000 0 +3000 0.015625 +4000 0.015625 +5000 0.03125 +6000 0.046875 +7000 0.0625 diff --git a/sem_3/algo/tp1-done/PROG_TP1/sm3.dat b/sem_3/algo/tp1-done/PROG_TP1/sm3.dat new file mode 100644 index 0000000..811f1f9 --- /dev/null +++ b/sem_3/algo/tp1-done/PROG_TP1/sm3.dat @@ -0,0 +1,10 @@ +100 0 +200 0 +300 0 +400 0 +500 0 +600 0 +700 0 +800 0 +900 0 +1000 0 diff --git a/sem_3/algo/tp1-done/PROG_TP1/sm4.dat b/sem_3/algo/tp1-done/PROG_TP1/sm4.dat new file mode 100644 index 0000000..811f1f9 --- /dev/null +++ b/sem_3/algo/tp1-done/PROG_TP1/sm4.dat @@ -0,0 +1,10 @@ +100 0 +200 0 +300 0 +400 0 +500 0 +600 0 +700 0 +800 0 +900 0 +1000 0 diff --git a/sem_3/algo/tp1-done/PROG_TP1/tp1 b/sem_3/algo/tp1-done/PROG_TP1/tp1 Binary files differnew file mode 100644 index 0000000..8cce618 --- /dev/null +++ b/sem_3/algo/tp1-done/PROG_TP1/tp1 diff --git a/sem_3/algo/tp1-done/PROG_TP1/trace1.gnu b/sem_3/algo/tp1-done/PROG_TP1/trace1.gnu new file mode 100644 index 0000000..a7f446a --- /dev/null +++ b/sem_3/algo/tp1-done/PROG_TP1/trace1.gnu @@ -0,0 +1,5 @@ +set ylabel "secondes" +plot "sm4.dat" with lines, "sm3.dat" with lines, "sm2.dat" with lines, "sm1.dat" with lines +pause -1 "Appuyez sur RETURN pour continuer" +exit + diff --git a/sem_3/algo/tp1-done/PROG_TP1/trace2.gnu b/sem_3/algo/tp1-done/PROG_TP1/trace2.gnu new file mode 100644 index 0000000..ba4de89 --- /dev/null +++ b/sem_3/algo/tp1-done/PROG_TP1/trace2.gnu @@ -0,0 +1,5 @@ +set ylabel "secondes" +plot "sm4.dat" with lines, "sm3.dat" with lines, "sm2.dat" with lines +pause -1 "Appuyez sur RETURN pour continuer" +exit + diff --git a/sem_3/algo/tp1-done/PROG_TP1/trace3.gnu b/sem_3/algo/tp1-done/PROG_TP1/trace3.gnu new file mode 100644 index 0000000..1907656 --- /dev/null +++ b/sem_3/algo/tp1-done/PROG_TP1/trace3.gnu @@ -0,0 +1,5 @@ +set ylabel "secondes" +plot "sm4.dat" with lines, "sm3.dat" with lines +pause -1 "Appuyez sur RETURN pour continuer" +exit + diff --git a/sem_3/algo/tp1-done/énoncéTP1.pdf b/sem_3/algo/tp1-done/énoncéTP1.pdf Binary files differnew file mode 100644 index 0000000..bdd788a --- /dev/null +++ b/sem_3/algo/tp1-done/énoncéTP1.pdf diff --git a/sem_3/algo/tp2/fichierTP2.cpp b/sem_3/algo/tp2/fichierTP2.cpp new file mode 100644 index 0000000..3a73196 --- /dev/null +++ b/sem_3/algo/tp2/fichierTP2.cpp @@ -0,0 +1,214 @@ +#include <iostream> +#include <fstream> +#include <string> +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include "progListeSC.h" +using namespace std; + +// DERNIERLSC ET ESTTRIEELSC +// Res : Renvoie l'adresse de la derniere cellule de la liste non vide L +ListeSC dernierLSC(ListeSC L){ + while ( L->succ != NULL){ + L=L->succ; + } + return L; +} + +// Res : Renvoie 1 si L est une ListeSC triee, 0 sinon +int estTrieeLSC(ListeSC L){ + while(L->succ != NULL){ + if (L->info > L->succ->info) { + return 0; + } + L=L->succ; + } + return 1; +} + + +// OTERREPETITION +// Res : Supprime de la ListeSC L tous les elements consecutifs egaux +// Opere en modifiant le chainage de la ListeSC L +// version iterative +void oterRepetitionLSC(ListeSC L){ + if (L->succ==NULL || L== NULL) return; + while ( L->succ != NULL){ + if (L->info == L->succ->info ) { + ListeSC tmp= L->succ; + L->succ=L->succ->succ; + delete tmp; + } + if ( L->succ != NULL ) L=L->succ; + } +} + +// Res : Supprime de la ListeSC L tous les elements consecutifs egaux +// Opere en modifiant le chainage de la ListeSC L +// version recursive +void oterRepetitionLSCR(ListeSC L){ + if ( L -> succ == NULL || L== NULL) return; + if ( L->succ->info==L->info){ + ListeSC tmp = L; + L->succ=L->succ->succ; + delete tmp; + } + oterRepetitionLSC(L->succ); + return; +} + + +// CONCATENATION DE 2 LISTES +// Res : Modifie la liste L1 en la concatenant avec la liste l2 +// Opere en modifiant le chainage de la listeSC L1 +// Version utilisant la fonction dernierLSC +void concatLSC(ListeSC L1,ListeSC L2){ + ListeSC tmp = dernierLSC(L1); + tmp->succ = L2; + return; +} + +// Res : Renvoie la ListeSC obtenue par concatenation des ListeSC L1 et L2 +// Opere en recopiant les elements des 2 listeSC L1 et L2 +// complexite : ??? +ListeSC concatLSCCopie(ListeSC L1,ListeSC L2){ + ListeSC L3=NULL; + while ( L1 != NULL) { + insererFinLSC(L3, L1->info); + L1 = L1->succ; + } + while (L2 != NULL){ + insererFinLSC(L3,L2->info); + L2=L2->succ; + } + return L3; +} + + +int main(int argc, char *argv[]){ + ListeSC l1,l2,l3; + int q; + + cout << "Numero de la question traitee (1/2/3/4/5) ? "; + cin >> q; + switch (q){ + case 1 : // Test des operations de base sur les listes + l1 = lireLSC(); + + // insertion d'un element de valeur 11 en derniere position de la liste l1 + // en utilisant insererFinLSC + // Completez + insererFinLSC(l1, 11); + + + cout << "Insertion de 11 en derniere position "; afficherLSC(l1); + + // insertion d'un element de valeur 22 en 2eme position de la liste l1 + // en utilisant insererApresLSC + // Completez + insererApresLSC(l1, l1,22); + + + cout << "Insertion de 22 en 2eme position ";afficherLSC(l1); + + // insertion d'un element de valeur 33 en 2eme position de la liste l1 + // sans utiliser insererApresLSC + // Completez + l1=creerLSC(l1->info, creerLSC(33, l1->succ)); + + + cout << "Insertion de 33 en 2eme position ";afficherLSC(l1); + + // Suppression du 2eme element de la liste en utilisant supprimerLSC + // Completez + supprimerLSC(l1, l1->succ); + + + cout << "Suppression du 2eme element "; afficherLSC(l1); + + // Suppression du 2eme element de la liste sans utiliser supprimerLSC + // Completez + if ( l1->succ!=NULL){ + ListeSC templist = l1->succ; + l1->succ = l1->succ->succ; + delete templist; + } + + cout << "Suppression du 2eme element "; afficherLSC(l1); + + // Inversion des valeurs des 2 premiers elements + // en modifiant les champs info (sans modifier le chainage) + // Completez + if (l1->succ != NULL){ + int tmp = l1->succ->info; + l1->succ->info=l1->info; + l1->info= tmp; + } + + + cout << "Inversion des valeurs des 2 premiers elements " ; afficherLSC(l1); + + // Inversion des 2 premiers elements + // en modifiant les champs succ (le chainage) + // Completez + if ( l1->succ != NULL) { + ListeSC templist; + templist = l1; + l1 = l1->succ; + templist->succ = l1->succ; + l1->succ= templist; + } + + + cout << "Inversion des 2 premiers elements "; afficherLSC(l1); + break; + + case 2 : // Test des fonctions estTrieeLSC et dernierLSC + l1 = lireLSC(); + if (estTrieeLSC(l1)) cout << "Cette liste est triee\n"; + else cout << "Cette liste n'est pas triee\n"; + if (l1 != NULL) + cout << "La valeur de son dernier element est " << dernierLSC(l1)->info << endl; + break; + + case 3: // Test des fonctions oterRepetitionLSC + l1 = lireLSC(); + oterRepetitionLSC(l1); + cout << "Liste sans repetition (version iterative) :\n"; + afficherLSC(l1); + l1 = lireLSC(); + oterRepetitionLSCR(l1); + cout << "Liste sans repetition (version recursive) :\n"; + afficherLSC(l1); + break; + + case 4 : // Test de la premiere fonction de concatenation de listes + l1 = lireLSC(); + l2 = lireLSC(); + concatLSC(l1,l2); + cout << "Concatenation des 2 listes (en modifiant le chainage) :\n"; afficherLSC(l1); + if ((l1 != NULL) && (l2 != NULL) ) + cout << "Adresse derniere cellule de l1 : " << (void *) dernierLSC(l1) << ", de l2 : "<< (void *) dernierLSC(l2) << endl; + cout << " Ajout de 44 en fin de la liste l1\n"; + insererFinLSC(l1,44); + cout << "Nouvelle valeur de l1:"; afficherLSC(l1); cout << endl; + cout << "Nouvelle valeur de l2: "; afficherLSC(l2); cout << endl; + break; + + case 5 : // Test des fonctions de concatenation de listes + l1 = lireLSC(); + l2 = lireLSC(); + l3 = concatLSCCopie(l1,l2); + cout << "Concatenation des 2 listes (par recopie des listes) : "; afficherLSC(l3); cout << endl; + if ((l1 != NULL) && (l2 != NULL) ) + cout << "Adresse derniere cellule de l1 : " << (void *) dernierLSC(l1) << " , de l2 : " << (void *) dernierLSC(l2) << ", de l3 : " << (void *) dernierLSC(l3) << endl; + cout << " Ajout de 55 en fin de la liste l1\n"; + insererFinLSC(l1,55); + cout << "Nouvelle valeur de l1: "; afficherLSC(l1); cout << endl; + cout << "Nouvelle valeur de l2: "; afficherLSC(l2); cout << endl; + cout << "Nouvelle valeur de l3: "; afficherLSC(l3); cout << endl; + break; + } + return 0; +} diff --git a/sem_3/algo/tp2/prog b/sem_3/algo/tp2/prog Binary files differnew file mode 100644 index 0000000..f4f6684 --- /dev/null +++ b/sem_3/algo/tp2/prog diff --git a/sem_3/algo/tp2/progListeSC.cpp b/sem_3/algo/tp2/progListeSC.cpp new file mode 100644 index 0000000..dd81a27 --- /dev/null +++ b/sem_3/algo/tp2/progListeSC.cpp @@ -0,0 +1,104 @@ +// progListeSC.c +#include <iostream> +#include <fstream> +#include <assert.h> +#include <stdlib.h> +#include <stdio.h> +#include "progListeSC.h" + +using namespace std; + + +int estVideLSC(ListeSC l) +{ return (l==NULL);} + +ListeSC creerLSC(int val, ListeSC succ){ + ListeSC l = new CelluleSC; + l->info=val; + l->succ=succ; + return l;} + +void insererDebutLSC(ListeSC &p, int val){ + p=creerLSC(val,p); + return;} + +void insererApresLSC(ListeSC &l, ListeSC p, int val){ + assert((l)!=NULL); assert(p!=NULL); + (p->succ)=creerLSC(val,(p->succ)); + return;} + +void insererFinLSC(ListeSC &p, int val){ + if (p==NULL) + p=creerLSC(val,NULL); + else + insererFinLSC(p->succ,val); + return; +} + +ListeSC predecesseurLSC(ListeSC L, ListeSC P){ + assert(L!=NULL); + assert(P!=NULL); + + if (L->succ==P){return L;} + else {return predecesseurLSC(L->succ,P);} +} + +void supprimerLSC(ListeSC &L, ListeSC P){ + assert(L!=NULL); + assert(P!=NULL); + + if (L==P){L = L->succ;} + else { + predecesseurLSC(L,P)->succ = P->succ; + } + delete P; + return;} + +void supprimerDebutLSC(ListeSC &L){ + ListeSC P; + assert(L!=NULL); + + P=L; + L=L->succ; + delete P; + + return;} + + +void supprimerFinLSC(ListeSC &L){ + assert(L!=NULL); + + if (L->succ==NULL){ + delete L; + L=NULL;} + else { + ListeSC P=L,Q; + while ((P->succ)->succ!=NULL){ + P=P->succ;} + Q=P->succ; + P->succ=NULL; + delete Q;} + return;} + + + +void afficherLSC(ListeSC l){ + cout << "ListeSC : "; + while (! estVideLSC(l)){ + cout << l->info << " "; + l=l->succ;} + cout << endl; + return;} + +ListeSC lireLSC(){ + ListeSC l; + int i; + cout << "Entrez les éléments d'une liste d'entiers (0 pour finir)\n"; + l=NULL; + cin >> i; + while (i!=0) { + insererFinLSC(l,i); + cin >> i; + } + return l; +} diff --git a/sem_3/algo/tp2/progListeSC.h b/sem_3/algo/tp2/progListeSC.h new file mode 100644 index 0000000..c259352 --- /dev/null +++ b/sem_3/algo/tp2/progListeSC.h @@ -0,0 +1,56 @@ + +//* ListeSC.h * +// Implantation du type Liste d'entiers Simplement Chainée + +#ifndef LISTESC_H +#define LISTESC_H + +typedef struct cellule { + int info; + struct cellule *succ;} CelluleSC; + +typedef CelluleSC *ListeSC; + + +// Res : renvoie 1 si L est la liste vide, renvoie 1 sinon +int estVideLSC(ListeSC L ); + +// Res : renvoie une ListeSC dont le premier élément est e et la suite de la liste L +ListeSC creerLSC(int e, ListeSC L); + +// Res : modifie la ListeSC L en y insérant en première place l'élément e +void insererDebutLSC(ListeSC &L, int e); + +// Donnée : L est une ListeSC non vide, P l'adresse d'un élément de L, e un entier +// Res : insère dans la liste L après l'élément d'adresse P 1 élément de valeur e +void insererApresLSC(ListeSC &L, ListeSC P, int e); + +// Res : modifie la listeSC L en y insérant en dernière place l'élément e +void insererFinLSC(ListeSC &L, int e); + +// Donnée : L est une ListeSC non Vide ; +// P est un pointeur non vide vers une cellule de la liste L +// L != P +// Res : renvoie l'adresse de la cellule précédant dans L celle pointée pas P +ListeSC predecesseurLSC(ListeSC L, ListeSC P); + +// Donnée : L est une ListeSC non Vide ; +// P est un pointeur non vide vers une cellule de la liste L +// Res : modifie L en supprimant de L la cellule pointée pas P +void supprimerLSC(ListeSC &L, ListeSC P); + +// Donnée : L est une ListeSC non Vide ; +// Res : modifie L en supprimant son dernier élément +void supprimerFinLSC(ListeSC &L); + +// Donnée : L est une ListeSC non Vide ; +// Res : modifie L en supprimant son premier élément +void supprimerDebutLSC(ListeSC &L); + +// Res : affiche la liste L +void afficherLSC(ListeSC L); + +// Res : renvoie la ListeSC des éléments saisis au clavier +ListeSC lireLSC(); + +#endif //LISTESC_H diff --git a/sem_3/algo/tp2/énoncé TP2.pdf b/sem_3/algo/tp2/énoncé TP2.pdf Binary files differnew file mode 100644 index 0000000..9d961dc --- /dev/null +++ b/sem_3/algo/tp2/énoncé TP2.pdf diff --git a/sem_3/project/Documents du Projet-20171011/SujetBatailleNavale.pdf b/sem_3/project/Documents du Projet-20171011/SujetBatailleNavale.pdf Binary files differnew file mode 100644 index 0000000..bdcfa0a --- /dev/null +++ b/sem_3/project/Documents du Projet-20171011/SujetBatailleNavale.pdf diff --git a/sem_3/project/Documents du Projet-20171011/test-piece.cpp b/sem_3/project/Documents du Projet-20171011/test-piece.cpp new file mode 100644 index 0000000..fcbff74 --- /dev/null +++ b/sem_3/project/Documents du Projet-20171011/test-piece.cpp @@ -0,0 +1,65 @@ +#include "window.h" + + +void myprogram(){ + int ch; + int h=10,w=10; + Window menu(3,30,1,0); + Window plateau(h,w,1,6); + menu.setCouleurBordure(BRED); + plateau.setCouleurBordure(BBLUE); + + menu.print(1,1,"Tapez q pour quitter !!!",WRED); + + int x=w/2,y=h/2; + char p='X'; + Color col=WBLUE; + plateau.print(x,y,p,col); + + while((ch = getch()) != 'q') + { + switch (ch) { + case '1': + col=BMAGENTA; + break; + case '2': + col=WCYAN; + break; + case 'c': + plateau.clear(); + break; + case KEY_UP: + plateau.print(x,y,' '); + plateau.print(x,--y,p,col); + break; + case KEY_DOWN: + plateau.print(x,y,' '); + plateau.print(x,++y,p,col); + break; + case KEY_LEFT: + plateau.print(x,y,' '); + plateau.print(--x,y,p,col); + break; + case KEY_RIGHT: + plateau.print(x,y,' '); + plateau.print(++x,y,p,col); + break; + case '\n': + x=w/2,y=h/2; + plateau.print(x,y,p,col); + break; + case '\t': + Color tmp= menu.getCouleurBordure(); + menu.setCouleurBordure(plateau.getCouleurBordure()); + plateau.setCouleurBordure(tmp); + break; + } + } +} + +int main(){ + startProgramX(); + myprogram(); + stopProgramX(); + return 0; +} diff --git a/sem_3/project/Documents du Projet-20171011/window.cpp b/sem_3/project/Documents du Projet-20171011/window.cpp new file mode 100644 index 0000000..65694a7 --- /dev/null +++ b/sem_3/project/Documents du Projet-20171011/window.cpp @@ -0,0 +1,114 @@ +#include "window.h" + + +void init_colors(void) +{ + start_color(); + init_pair(WBLACK, COLOR_WHITE, COLOR_BLACK); + init_pair(WCYAN, COLOR_WHITE, COLOR_CYAN); + init_pair(WBLUE, COLOR_WHITE, COLOR_BLUE); + init_pair(WYELLOW, COLOR_WHITE, COLOR_YELLOW); + init_pair(WGREEN, COLOR_WHITE, COLOR_GREEN); + init_pair(WMAGENTA, COLOR_WHITE, COLOR_MAGENTA); + init_pair(WRED, COLOR_WHITE, COLOR_RED); + init_pair(BWHITE, COLOR_BLACK, COLOR_WHITE); + init_pair(BCYAN, COLOR_BLACK, COLOR_CYAN); + init_pair(BBLUE, COLOR_BLACK, COLOR_BLUE); + init_pair(BYELLOW, COLOR_BLACK, COLOR_YELLOW); + init_pair(BGREEN, COLOR_BLACK, COLOR_GREEN); + init_pair(BMAGENTA, COLOR_BLACK, COLOR_MAGENTA); + init_pair(BRED, COLOR_BLACK, COLOR_RED); +} + + +void startProgramX() { + initscr(); // initialize curses + cbreak(); // pass key presses to program, but not signals + noecho(); // don't echo key presses to screen + keypad(stdscr, TRUE); // allow arrow keys + timeout(0); // no blocking on getch() + curs_set(0); // set the cursor to invisible + init_colors(); +} + +void stopProgramX() { + refresh(); + getch(); + endwin(); +} + + + +void Window::update() const{ + wrefresh(win); + wrefresh(frame); + refresh(); +} + + +Window::Window(int h,int w, int x, int y, char c) + : height(h), width(w), startx(x), starty(y), bord(c) +{ + colorwin=WCYAN; + colorframe=WBLACK; + frame=newwin(h+2,w+2,y,x); + win=subwin(frame,h,w,y+1,x+1); + wbkgd(frame,COLOR_PAIR(colorwin)); + wbkgd(win,COLOR_PAIR(colorframe)); + wborder(frame, c,c,c,c,c,c,c,c); + wattron(win,COLOR_PAIR(colorwin)); + wattron(frame,COLOR_PAIR(colorframe)); + update(); +} + +Window::~Window(){ + wborder(frame, ' ', ' ', ' ',' ',' ',' ',' ',' '); + wattroff(win,COLOR_PAIR(colorwin)); + wattroff(win,COLOR_PAIR(colorframe)); + werase(win); + update(); + delwin(win); +} + +void Window::print(int x, int y, std::string s, Color c) const { + wattron(win,COLOR_PAIR(c)); + mvwprintw(win,y,x,s.c_str()); + wattroff(win,COLOR_PAIR(c)); + update(); +} +void Window::print(int x, int y, char s, Color c) const{ + wattron(win,COLOR_PAIR(c)); + mvwaddch(win,y,x,s); + wattroff(win,COLOR_PAIR(c)); + update(); +} +void Window::print(int x, int y, std::string s) const{ + mvwprintw(win,y,x,s.c_str()); + update(); +} +void Window::print(int x, int y, char s) const{ + mvwaddch(win,y,x,s); + update(); +} + + +int Window::getX() const { return startx;} +int Window::getY() const { return starty;} +int Window::getHauteur() const { return height;} +int Window::getLargeur() const { return width;} +Color Window::getCouleurBordure() const{ return colorframe;} +Color Window::getCouleurFenetre() const{ return colorwin;} +void Window::setCouleurBordure(Color c){ + colorframe=c; + wattron(frame,COLOR_PAIR(colorframe)); + wborder(frame, bord,bord,bord,bord,bord,bord,bord,bord); + update(); +} +void Window::setCouleurFenetre(Color c){ + colorwin=c; + wattron(win,COLOR_PAIR(colorwin)); + wbkgd(win,COLOR_PAIR(colorwin)); + update(); +} + +void Window::clear() const{ werase(win); update(); } diff --git a/sem_3/project/Documents du Projet-20171011/window.h b/sem_3/project/Documents du Projet-20171011/window.h new file mode 100644 index 0000000..124e2eb --- /dev/null +++ b/sem_3/project/Documents du Projet-20171011/window.h @@ -0,0 +1,85 @@ +#ifndef __WINDOW_H +#define __WINDOW_H + +extern "C" { +#include <curses.h> +} +#include <string> + +// Ensemble de couleurs possibles (fond+texte) +enum Color { + WBLACK, // couleur fond = noir , couleur texte = blanc + WCYAN, // couleur fond = cyan, couleur texte = blanc + WBLUE, // couleur fond = bleu, couleur texte = blanc + WYELLOW, // couleur fond = jaune, couleur texte = blanc + WGREEN, // couleur fond = vert, couleur texte = blanc + WMAGENTA,// couleur fond = magenta, couleur texte = blanc + WRED, // couleur fond = rouge, couleur texte = blanc + BWHITE, // couleur fond = blanc, couleur texte = blanc + BCYAN, // couleur fond = cyan, couleur texte = noir + BBLUE, // couleur fond = bleu, couleur texte = noir + BYELLOW, // couleur fond = jaune, couleur texte = noir + BGREEN, // couleur fond = vert, couleur texte = noir + BMAGENTA,// couleur fond = magenta, couleur texte = noir + BRED, // couleur fond = rouge, couleur texte = noir +}; + + + +// fonction pour demarrer le mode console graphique +void startProgramX(); +// fonction pour arreter le mode console graphique +void stopProgramX(); + + +class Window { + private: + int height,width,startx,starty; + WINDOW* win, *frame; + Color colorwin, colorframe; + char bord; + void update() const; + + public: + + // constructeur d'un fenetre de hauteur=h, largeur=w dont le coin superieur gauche + // a pour coordonnée (x,y), le caractère c est utilisé pour définir la bordure + Window(int h,int w, int x, int y, char c='+'); + + ~Window(); + + // fonction permettant d'afficher une variable s de type (string ou char) + // à la position (x,y) dans la fenetre. + // si un couleur est spécifié l'affichage utilise cette couleur, sinon la couleur de la fenêtre est utilisée + void print(int x, int y, std::string s, Color c) const; + void print(int x, int y, char s, Color c) const; + void print(int x, int y, std::string s) const; + void print(int x, int y, char s) const; + + + // accesseurs + int getX() const; // récupère l'abscisse du coin supérieur gauche de la fenêtre + int getY() const; // récupère l'ordonnée du coin supérieur gauche de la fenêtre + int getHauteur() const ; // récupère la hauteur de la fenêtre + int getLargeur() const ; // récupère la largeur de la fenêtre + + Color getCouleurBordure() const; // récupère la couleur de la bordure + Color getCouleurFenetre() const; // récupère la couleur de la fenêtre + void setCouleurBordure(Color); // modifie la couleur de la bordure + void setCouleurFenetre(Color); // modifie la couleur de la fenêtre (ATTENTION, tout le contenu de la fenêtre prend la couleur) + + void clear() const; // enleve tout le contenu de la fenêtre + +}; + + + + + + + + + + + +#endif |
