lab.cpp/ex3.cpp

68 lines
1.5 KiB
C++
Raw Normal View History

2016-03-03 18:30:01 +00:00
#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;
}