#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