This commit is contained in:
xdrm-brackets 2016-03-03 19:30:01 +01:00
parent 7de48e09ce
commit 462d87e081
17 changed files with 318 additions and 0 deletions

9
ex1.cpp Normal file
View File

@ -0,0 +1,9 @@
#include <iostream>
using namespace std;
int main(){
cout << "Hello World!" << endl;
return 0;
}

16
ex2.cpp Normal file
View File

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

67
ex3.cpp Normal file
View File

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

23
ex3/Addition.cpp Normal file
View File

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

9
ex3/Addition.h Normal file
View File

@ -0,0 +1,9 @@
#include "Operator.h"
class Addition : public Operator{
public:
Addition();
std::string getLibelle();
float* calc();
};

22
ex3/Division.cpp Normal file
View File

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

9
ex3/Division.h Normal file
View File

@ -0,0 +1,9 @@
#include "Operator.h"
class Division : public Operator{
public:
Division();
std::string getLibelle();
float* calc();
};

View File

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

View File

@ -0,0 +1,9 @@
#include "Operator.h"
class DivisionEuclidienne : public Operator{
public:
DivisionEuclidienne();
std::string getLibelle();
float* calc();
};

23
ex3/Multiplication.cpp Normal file
View File

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

10
ex3/Multiplication.h Normal file
View File

@ -0,0 +1,10 @@
#include "Operator.h"
class Multiplication : public Operator{
public:
Multiplication();
std::string getLibelle();
float* calc();
};

60
ex3/Operator.h Normal file
View File

@ -0,0 +1,60 @@
#ifndef OPERATOR_H
#define OPERATOR_H
#include <string>
#include <stdlib.h>
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

25
ex3/Soustraction.cpp Normal file
View File

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

9
ex3/Soustraction.h Normal file
View File

@ -0,0 +1,9 @@
#include "Operator.h"
class Soustraction : public Operator{
public:
Soustraction();
std::string getLibelle();
float* calc();
};

BIN
exec/ex1 Executable file

Binary file not shown.

BIN
exec/ex2 Executable file

Binary file not shown.

BIN
exec/ex3 Executable file

Binary file not shown.