diff --git a/README.md b/README.md index 6b30864..daa39f6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,13 @@ Lab de prog. en C++. ==================== + + +[ex1] Hello World + +[ex2] string + << + +[ex3] Calculatrice modulaire + +[ex4] Fichiers + +[tp1] Mot mystere \ No newline at end of file diff --git a/ex3.cpp b/ex3.cpp index 3fd777d..50aa22a 100644 --- a/ex3.cpp +++ b/ex3.cpp @@ -1,11 +1,13 @@ #include #include +#include #include "ex3/Addition.cpp" #include "ex3/Soustraction.cpp" #include "ex3/Multiplication.cpp" #include "ex3/Division.cpp" #include "ex3/DivisionEuclidienne.cpp" +#include "ex3/Trinome.cpp" using namespace std; @@ -13,31 +15,34 @@ using namespace std; int main(){ int choix(0); + char input[8] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}; + char output[8] = {'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'}; + /* [1] On initialise les operations =========================================================*/ - Operator *operations[5]; + vector operations; // On ajoute les operations; - operations[0] = new Addition(); - operations[1] = new Soustraction(); - operations[2] = new Multiplication(); - operations[3] = new Division(); - operations[4] = new DivisionEuclidienne(); - - int nbOp = sizeof(operations)/sizeof(Operator*); + operations.push_back( new Addition() ); + operations.push_back( new Soustraction() ); + operations.push_back( new Multiplication() ); + operations.push_back( new Division() ); + operations.push_back( new DivisionEuclidienne() ); + operations.push_back( new Trinome() ); /* [2] Choix de l'operation a executer =========================================================*/ do{ cout << " +-------------------------+" << endl; - for( int i = 0 ; i < nbOp ; i++ ) + for( int i = 0 ; i < operations.size() ; i++ ) cout << " + " << i << ") " << operations[i]->getLibelle() << endl; cout << " +-------------------------+" << endl; cout << " + Choix: "; cin >> choix; cout << endl << endl; - }while( choix < 0 || choix >= nbOp ); + cout << "=======================================" << endl; + }while( choix < 0 || choix >= operations.size() ); /* [3] On recupere les operandes pour le calcul @@ -46,7 +51,7 @@ int main(){ int countOp(0); while( operations[choix]->missingOperand() ){ - cout << "x" << countOp << " = "; + cout << input[countOp] << " = "; cin >> scanner; cout << endl; @@ -57,7 +62,7 @@ int main(){ float* result = operations[choix]->calc(); for( int i = 0 ; result[i] != '\0' ; i++ ) - cout << "y" << i << " = " << result[i] << endl; + cout << output[i] << " = " << result[i] << endl; return 0; } diff --git a/ex3/Addition.cpp b/ex3/Addition.cpp index 83c680e..9234e93 100644 --- a/ex3/Addition.cpp +++ b/ex3/Addition.cpp @@ -9,7 +9,7 @@ Addition::Addition(){ /* [1] Renvoie le nom du type de calcul =========================================================*/ std::string Addition::getLibelle(){ - return "Addition"; + return "a + b"; } /* [2] Effectue le calcul et renvoie le resultat diff --git a/ex3/Division.cpp b/ex3/Division.cpp index 54a4c44..cd408dd 100644 --- a/ex3/Division.cpp +++ b/ex3/Division.cpp @@ -9,7 +9,7 @@ Division::Division(){ /* [1] Renvoie le nom du type de calcul =========================================================*/ std::string Division::getLibelle(){ - return "Division"; + return "a / b"; } /* [2] Effectue le calcul et renvoie le resultat diff --git a/ex3/DivisionEuclidienne.cpp b/ex3/DivisionEuclidienne.cpp index 1cd1297..581a9f2 100644 --- a/ex3/DivisionEuclidienne.cpp +++ b/ex3/DivisionEuclidienne.cpp @@ -1,5 +1,7 @@ #include "DivisionEuclidienne.h" +#include + /* [0] CONSTRUCTEUR =========================================================*/ DivisionEuclidienne::DivisionEuclidienne(){ @@ -9,7 +11,7 @@ DivisionEuclidienne::DivisionEuclidienne(){ /* [1] Renvoie le nom du type de calcul =========================================================*/ std::string DivisionEuclidienne::getLibelle(){ - return "Division euclidienne"; + return "a / b = ib + j"; } /* [2] Effectue le calcul et renvoie le resultat diff --git a/ex3/Multiplication.cpp b/ex3/Multiplication.cpp index f8fb338..89848a7 100644 --- a/ex3/Multiplication.cpp +++ b/ex3/Multiplication.cpp @@ -9,7 +9,7 @@ Multiplication::Multiplication(){ /* [1] Renvoie le nom du type de calcul =========================================================*/ std::string Multiplication::getLibelle(){ - return "Multiplication"; + return "a * b"; } /* [2] Effectue le calcul et renvoie le resultat diff --git a/ex3/Soustraction.cpp b/ex3/Soustraction.cpp index 9c82e51..b200d97 100644 --- a/ex3/Soustraction.cpp +++ b/ex3/Soustraction.cpp @@ -10,7 +10,7 @@ Soustraction::Soustraction(){ /* [1] Renvoie le nom du type de calcul =========================================================*/ std::string Soustraction::getLibelle(){ - return "Soustraction"; + return "a - b"; } /* [2] Effectue le calcul et renvoie le resultat diff --git a/ex3/Trinome.cpp b/ex3/Trinome.cpp new file mode 100644 index 0000000..783d2c1 --- /dev/null +++ b/ex3/Trinome.cpp @@ -0,0 +1,48 @@ +#include "Trinome.h" + +#include +#include + +using namespace std; + +/* [0] CONSTRUCTEUR +=========================================================*/ +Trinome::Trinome(){ + this->init(3); +} + +/* [1] Renvoie le nom du type de calcul +=========================================================*/ +string Trinome::getLibelle(){ + return "ax^2 + bx + c = 0"; +} + +/* [2] Effectue le calcul et renvoie le resultat +=========================================================*/ +float* Trinome::calc(){ + const int a( this->operands[0] ), + b( this->operands[1] ), + c( this->operands[2] ); + + float delta = pow(b,2) - 4*a*c; + + // DELTA > 0 -> 2 racines + if( delta > 0 ){ + this->result = (float*) malloc(2*sizeof(float)); + + this->result[0] = (-b-sqrt(delta)) / (2*a); + this->result[1] = (-b+sqrt(delta)) / (2*a); + + // DELTA = 0 -> 1 racine + }else if( delta == 0 ){ + this->result = (float*) malloc(2*sizeof(float)); + + this->result[0] = (-b) / (2*a); + + // DELTA < 0 -> 0 racine + }else{ + this->result = (float*) malloc(0*sizeof(float)); + } + + return this->result; +} \ No newline at end of file diff --git a/ex3/Trinome.h b/ex3/Trinome.h new file mode 100644 index 0000000..4ed5f41 --- /dev/null +++ b/ex3/Trinome.h @@ -0,0 +1,9 @@ +#include "Operator.h" + + +class Trinome : public Operator{ + public: + Trinome(); + std::string getLibelle(); + float* calc(); +}; \ No newline at end of file diff --git a/ex4.cpp b/ex4.cpp new file mode 100644 index 0000000..6e805a3 --- /dev/null +++ b/ex4.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +using namespace std; + + +/* [1] Lecture de fichier +=========================================================*/ +int main(){ + + // On instancie notre stream + ofstream fichier("ex4/ex4.txt"); + + // On verifie qu'il n'y a aucune erreur + if( !fichier ) return -1; + + fichier << "MON FICHIER ECRIT !!!" << endl; + fichier << "Hehe" << endl << endl; + fichier << "Cool!" << endl; + + + return 0; +} \ No newline at end of file diff --git a/ex4/ex4.txt b/ex4/ex4.txt new file mode 100644 index 0000000..c9e7573 --- /dev/null +++ b/ex4/ex4.txt @@ -0,0 +1,4 @@ +MON FICHIER ECRIT !!! +Hehe + +Cool! diff --git a/exec/ex3 b/exec/ex3 index 5202a5e..23e1d11 100755 Binary files a/exec/ex3 and b/exec/ex3 differ diff --git a/exec/ex4 b/exec/ex4 new file mode 100755 index 0000000..80e97d6 Binary files /dev/null and b/exec/ex4 differ diff --git a/exec/tp1 b/exec/tp1 new file mode 100755 index 0000000..a7d6eab Binary files /dev/null and b/exec/tp1 differ diff --git a/tp1.cpp b/tp1.cpp new file mode 100644 index 0000000..a96ef57 --- /dev/null +++ b/tp1.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +using namespace std; + + +int main(){ + + /* [0] CONSTANTES + =========================================================*/ + const string dict_filename = "tp1/dict"; + ifstream dict_read( dict_filename.c_str() ); + + + /* [0] VARIABLES + =========================================================*/ + string word; + string shuffled; + + /* [1] Demande du mot + =========================================================*/ + s + + /* [2] Essai de l'utilisateur + =========================================================*/ + + + /* [3] Resultat + =========================================================*/ + + return 0; +} \ No newline at end of file diff --git a/tp1/dict b/tp1/dict new file mode 100644 index 0000000..e69de29