lab.cpp/ex3.cpp

77 lines
2.0 KiB
C++
Raw Permalink Normal View History

2016-03-03 18:30:01 +00:00
#include <iostream>
#include <string>
2016-03-04 07:49:31 +00:00
#include <vector>
2016-03-03 18:30:01 +00:00
#include "ex3/Addition.cpp"
#include "ex3/Soustraction.cpp"
#include "ex3/Multiplication.cpp"
#include "ex3/Division.cpp"
#include "ex3/DivisionEuclidienne.cpp"
2016-03-04 07:49:31 +00:00
#include "ex3/Trinome.cpp"
2016-03-04 13:18:01 +00:00
#include "ex3/Puissance.cpp"
#include "ex3/Racine.cpp"
2016-03-03 18:30:01 +00:00
using namespace std;
int main(){
int choix(0);
2016-03-04 07:49:31 +00:00
char input[8] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
char output[8] = {'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'};
2016-03-03 18:30:01 +00:00
/* [1] On initialise les operations
=========================================================*/
2016-03-04 07:49:31 +00:00
vector<Operator*> operations;
2016-03-03 18:30:01 +00:00
// On ajoute les operations;
2016-03-04 07:49:31 +00:00
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() );
2016-03-04 13:18:01 +00:00
operations.push_back( new Puissance() );
operations.push_back( new Racine() );
2016-03-03 18:30:01 +00:00
/* [2] Choix de l'operation a executer
=========================================================*/
do{
cout << " +-------------------------+" << endl;
2016-03-04 07:49:31 +00:00
for( int i = 0 ; i < operations.size() ; i++ )
2016-03-03 18:30:01 +00:00
cout << " + " << i << ") " << operations[i]->getLibelle() << endl;
cout << " +-------------------------+" << endl;
cout << " + Choix: ";
cin >> choix;
cout << endl << endl;
2016-03-04 07:49:31 +00:00
cout << "=======================================" << endl;
}while( choix < 0 || choix >= operations.size() );
2016-03-03 18:30:01 +00:00
/* [3] On recupere les operandes pour le calcul
=========================================================*/
float scanner;
int countOp(0);
while( operations[choix]->missingOperand() ){
2016-03-04 07:49:31 +00:00
cout << input[countOp] << " = ";
2016-03-03 18:30:01 +00:00
cin >> scanner;
cout << endl;
operations[choix]->addOperand(scanner);
countOp++;
}
float* result = operations[choix]->calc();
for( int i = 0 ; result[i] != '\0' ; i++ )
2016-03-04 07:49:31 +00:00
cout << output[i] << " = " << result[i] << endl;
2016-03-03 18:30:01 +00:00
return 0;
}