diff --git a/ex1.cpp b/ex1.cpp new file mode 100644 index 0000000..5d03069 --- /dev/null +++ b/ex1.cpp @@ -0,0 +1,9 @@ +#include + +using namespace std; + + +int main(){ + cout << "Hello World!" << endl; + return 0; +} \ No newline at end of file diff --git a/ex2.cpp b/ex2.cpp new file mode 100644 index 0000000..3ca2d50 --- /dev/null +++ b/ex2.cpp @@ -0,0 +1,16 @@ +#include +#include + +using namespace std; + + +int main(){ + int a = 10; + int b (11); + string stra("a="); + string strb("b="); + + cout << stra << a << endl; + cout << strb << b << endl; + return 0; +} \ No newline at end of file diff --git a/ex3.cpp b/ex3.cpp new file mode 100644 index 0000000..3fd777d --- /dev/null +++ b/ex3.cpp @@ -0,0 +1,67 @@ +#include +#include + +#include "ex3/Addition.cpp" +#include "ex3/Soustraction.cpp" +#include "ex3/Multiplication.cpp" +#include "ex3/Division.cpp" +#include "ex3/DivisionEuclidienne.cpp" + +using namespace std; + + +int main(){ + int choix(0); + + /* [1] On initialise les operations + =========================================================*/ + Operator *operations[5]; + + // 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*); + + + /* [2] Choix de l'operation a executer + =========================================================*/ + do{ + cout << " +-------------------------+" << endl; + for( int i = 0 ; i < nbOp ; i++ ) + cout << " + " << i << ") " << operations[i]->getLibelle() << endl; + cout << " +-------------------------+" << endl; + cout << " + Choix: "; + cin >> choix; + cout << endl << endl; + }while( choix < 0 || choix >= nbOp ); + + + /* [3] On recupere les operandes pour le calcul + =========================================================*/ + float scanner; + int countOp(0); + while( operations[choix]->missingOperand() ){ + + cout << "x" << countOp << " = "; + cin >> scanner; + cout << endl; + + operations[choix]->addOperand(scanner); + countOp++; + } + + float* result = operations[choix]->calc(); + + for( int i = 0 ; result[i] != '\0' ; i++ ) + cout << "y" << i << " = " << result[i] << endl; + + return 0; +} + + + + diff --git a/ex3/Addition.cpp b/ex3/Addition.cpp new file mode 100644 index 0000000..83c680e --- /dev/null +++ b/ex3/Addition.cpp @@ -0,0 +1,23 @@ +#include "Addition.h" + +/* [0] CONSTRUCTEUR +=========================================================*/ +Addition::Addition(){ + this->init(2); +} + +/* [1] Renvoie le nom du type de calcul +=========================================================*/ +std::string Addition::getLibelle(){ + return "Addition"; +} + +/* [2] Effectue le calcul et renvoie le resultat +=========================================================*/ +float* Addition::calc(){ + this->result = (float*) malloc(1*sizeof(float)); + + this->result[0] = this->operands[0]+this->operands[1]; + + return this->result; +} \ No newline at end of file diff --git a/ex3/Addition.h b/ex3/Addition.h new file mode 100644 index 0000000..b923ad4 --- /dev/null +++ b/ex3/Addition.h @@ -0,0 +1,9 @@ +#include "Operator.h" + + +class Addition : public Operator{ + public: + Addition(); + std::string getLibelle(); + float* calc(); +}; \ No newline at end of file diff --git a/ex3/Division.cpp b/ex3/Division.cpp new file mode 100644 index 0000000..54a4c44 --- /dev/null +++ b/ex3/Division.cpp @@ -0,0 +1,22 @@ +#include "Division.h" + +/* [0] CONSTRUCTEUR +=========================================================*/ +Division::Division(){ + this->init(2); +} + +/* [1] Renvoie le nom du type de calcul +=========================================================*/ +std::string Division::getLibelle(){ + return "Division"; +} + +/* [2] Effectue le calcul et renvoie le resultat +=========================================================*/ +float* Division::calc(){ + this->result = (float*) malloc(1*sizeof(float)); + + this->result[0] = this->operands[0]/this->operands[1]; + return this->result; +} \ No newline at end of file diff --git a/ex3/Division.h b/ex3/Division.h new file mode 100644 index 0000000..6354620 --- /dev/null +++ b/ex3/Division.h @@ -0,0 +1,9 @@ +#include "Operator.h" + + +class Division : public Operator{ + public: + Division(); + std::string getLibelle(); + float* calc(); +}; \ No newline at end of file diff --git a/ex3/DivisionEuclidienne.cpp b/ex3/DivisionEuclidienne.cpp new file mode 100644 index 0000000..1cd1297 --- /dev/null +++ b/ex3/DivisionEuclidienne.cpp @@ -0,0 +1,27 @@ +#include "DivisionEuclidienne.h" + +/* [0] CONSTRUCTEUR +=========================================================*/ +DivisionEuclidienne::DivisionEuclidienne(){ + this->init(2); +} + +/* [1] Renvoie le nom du type de calcul +=========================================================*/ +std::string DivisionEuclidienne::getLibelle(){ + return "Division euclidienne"; +} + +/* [2] Effectue le calcul et renvoie le resultat +=========================================================*/ +float* DivisionEuclidienne::calc(){ + int division = this->operands[0] / this->operands[1]; + int reste = (int)(this->operands[0]) % (int)(this->operands[1]); + + this->result = (float*) malloc(2*sizeof(float)); + + this->result[0] = (float) division; + this->result[1] = (float) reste; + + return this->result; +} \ No newline at end of file diff --git a/ex3/DivisionEuclidienne.h b/ex3/DivisionEuclidienne.h new file mode 100644 index 0000000..adfd788 --- /dev/null +++ b/ex3/DivisionEuclidienne.h @@ -0,0 +1,9 @@ +#include "Operator.h" + + +class DivisionEuclidienne : public Operator{ + public: + DivisionEuclidienne(); + std::string getLibelle(); + float* calc(); +}; \ No newline at end of file diff --git a/ex3/Multiplication.cpp b/ex3/Multiplication.cpp new file mode 100644 index 0000000..f8fb338 --- /dev/null +++ b/ex3/Multiplication.cpp @@ -0,0 +1,23 @@ +#include "Multiplication.h" + +/* [0] CONSTRUCTEUR +=========================================================*/ +Multiplication::Multiplication(){ + this->init(2); +} + +/* [1] Renvoie le nom du type de calcul +=========================================================*/ +std::string Multiplication::getLibelle(){ + return "Multiplication"; +} + +/* [2] Effectue le calcul et renvoie le resultat +=========================================================*/ +float* Multiplication::calc(){ + this->result = (float*) malloc(1*sizeof(float)); + + this->result[0] = this->operands[0]*this->operands[1]; + + return this->result; +} \ No newline at end of file diff --git a/ex3/Multiplication.h b/ex3/Multiplication.h new file mode 100644 index 0000000..c3c9b81 --- /dev/null +++ b/ex3/Multiplication.h @@ -0,0 +1,10 @@ +#include "Operator.h" + + + +class Multiplication : public Operator{ + public: + Multiplication(); + std::string getLibelle(); + float* calc(); +}; \ No newline at end of file diff --git a/ex3/Operator.h b/ex3/Operator.h new file mode 100644 index 0000000..5371fb7 --- /dev/null +++ b/ex3/Operator.h @@ -0,0 +1,60 @@ +#ifndef OPERATOR_H + #define OPERATOR_H + #include + #include + + + class Operator{ + public: + void init(int size); + void addOperand(float x); + bool missingOperand(); + + virtual std::string getLibelle(); + virtual float* calc(); + + int size; + + protected: + float *result; + float *operands; + }; + + + /* (1) Initialise les operandes */ + void Operator::init(int size){ + this->size = size; + this->operands = (float*) malloc(size*sizeof(float)); + + // On preremplis les operandes + for( int i = 0 ; i < size ; i++ ) + this->operands[i] = '\0'; + } + + + + /* (2) Ajoute une operande */ + void Operator::addOperand(float x){ + // On rempit la prochaine operande non-vide + for( int i = 0 ; i < this->size ; i++ ) + if( this->operands[i] == '\0' ){ // si vide + this->operands[i] = x; + break; + } + + } + + + /* (3) Verification qu'aucune operande ne manque */ + bool Operator::missingOperand(){ + // On verifie que toutes les operandes ont une valeur + for( int i = 0 ; i < this->size ; i++ ) + if( this->operands[i] == '\0' ) return true; // operandes ont une valeur + + return false; + } + + + std::string Operator::getLibelle(){ return "Operator"; }; + float* Operator::calc(){ return this->result; }; +#endif \ No newline at end of file diff --git a/ex3/Soustraction.cpp b/ex3/Soustraction.cpp new file mode 100644 index 0000000..9c82e51 --- /dev/null +++ b/ex3/Soustraction.cpp @@ -0,0 +1,25 @@ +#include "Soustraction.h" + + +/* [0] CONSTRUCTEUR +=========================================================*/ +Soustraction::Soustraction(){ + this->init(2); +} + +/* [1] Renvoie le nom du type de calcul +=========================================================*/ +std::string Soustraction::getLibelle(){ + return "Soustraction"; +} + +/* [2] Effectue le calcul et renvoie le resultat +=========================================================*/ +float* Soustraction::calc(){ + this->result = (float*) malloc(1*sizeof(float)); + + this->result[0] = this->operands[0]-this->operands[1]; + + + return this->result; +} \ No newline at end of file diff --git a/ex3/Soustraction.h b/ex3/Soustraction.h new file mode 100644 index 0000000..d05adc5 --- /dev/null +++ b/ex3/Soustraction.h @@ -0,0 +1,9 @@ +#include "Operator.h" + + +class Soustraction : public Operator{ + public: + Soustraction(); + std::string getLibelle(); + float* calc(); +}; \ No newline at end of file diff --git a/exec/ex1 b/exec/ex1 new file mode 100755 index 0000000..2d0c2b8 Binary files /dev/null and b/exec/ex1 differ diff --git a/exec/ex2 b/exec/ex2 new file mode 100755 index 0000000..ac6cdf8 Binary files /dev/null and b/exec/ex2 differ diff --git a/exec/ex3 b/exec/ex3 new file mode 100755 index 0000000..5202a5e Binary files /dev/null and b/exec/ex3 differ