void CalculatriceModele::getMean(int type){
    if(pile.size()>=1){
        Constante* a = pile.pop();
        if(typeid (*a).name()==typeid (Entier).name()){
            Entier* e = dynamic_cast<Entier*>(a);

            if(pile.size()>=e->GetEntier())
            {
                Rationnel nb_moyenne = e->inv();

                pile.push(e);
                emit getSum(type);

                a = pile.pop();
                Constante* res = nb_moyenne * a;
                qDebug()<<"res :"<<res->ConvertChaine();
                pile.push(res);
            }
            else{
                pile.push(a);
                logger1->Write(&LogMessage(ERROR,"taille pile insuffisante"));
                logger2->Write(&LogMessage(ERROR,"taille pile insuffisante"));
            }
        }
        else{
        logger1->Write(&LogMessage(ERROR,"type non conforme"));
        logger2->Write(&LogMessage(ERROR,"type non conforme"));
        }
        emit finOp(&pile);
    }
    else{
    logger1->Write(&LogMessage(ERROR,"taille pile insuffisante"));
    logger2->Write(&LogMessage(ERROR,"taille pile insuffisante"));
    }
}
Element* Calculateur::fact()
{
    if(typeid(*this->pileC->top()) == typeid(Expression))
    {
         throw std::logic_error("L'élément du haut de la pile est une expression");
    }
    if(typeid(*this->pileC->top()) == typeid(Complexe))
    {   qDebug()<<"on est en complexe";
         throw std::logic_error("La fonction factorielle ne s'applique pas au complexe");
    }
    if(typeid(*this->pileC->top()) != typeid(Entier))
    {   qDebug()<<"on est en non entier";
        throw std::logic_error("La fonction factorielle ne s'applique qu'au entier");
    }
    if(typeid(*this->pileC->top()) == typeid(Entier))
    {   qDebug()<<"on est en entier";
        Entier* m = dynamic_cast<Entier*>(this->pileC->pop()); /*!< module */
        int a,f;
        for(a=1,f=1;a<m->getXAsInt()+1;f*=a,a++);
        this->push(new Entier(f));
        delete m;
    }
    else
    {
        throw std::logic_error("L'élément du haut de la pile n'est pas un élement valide");
    }
}
Reelle::Reelle(const Entier& p,const Entier& m){
    /*Un réel ne peut pas être construit avec une mantisse nulle*/
    if(m.getValeur()==0){LitteraleException("Construction: Mantisse nulle !","Reelle");}
    else{value=p.getValeur();
            double mantisse=(double)m.getValeur();
           while(mantisse>=1)
            mantisse=mantisse/10.0;
            value+=mantisse;}
}
Element* Calculateur::sum()
{
   Entier* e = dynamic_cast<Entier*>(this->pop());
    qDebug()<<"ici ça marche";
    for(unsigned int i=0;i<e->getXAsInt()-1;i++)
    {
        this->addition();
    }
    qDebug()<<this->getPile()->top()->toQString();

}
Element& Reel::operator*(Element& e)
{
   {

    if(typeid(e) == typeid(Complexe))
    {
        Complexe& ecast = dynamic_cast<Complexe &>(e);

        if(typeid(*ecast.getRe()) == typeid(Entier))
        {
            Entier* ccast = dynamic_cast<Entier *>(ecast.getRe());
            Reel* tmp = new Reel(this->getX() * (float)ccast->getX());
            Reel* tmpim = new Reel(this->getXAsFloat() * ecast.getIm()->getXAsFloat());
            return *(new Complexe(tmp, tmpim));
        }
        else if(typeid(*ecast.getRe()) == typeid(Reel))
        {
            Reel* tmp = new Reel(this->getX() * ecast.getRe()->getXAsFloat());
            Reel* tmpim = new Reel(this->getXAsFloat() * ecast.getIm()->getXAsFloat());
            return *(new Complexe(tmp, tmpim));
        }
        else if(typeid(*ecast.getRe()) == typeid(Rationnel))
        {

            Reel* tmp = new Reel(this->getX()*(ecast.getRe()->getXAsFloat()/ecast.getRe()->getYAsFloat()));
            Reel* tmpim = new Reel(this->getXAsFloat()* (ecast.getIm()->getXAsFloat()/ecast.getIm()->getYAsFloat()));
            return *(new Complexe(tmp, tmpim));
        }
        else{}

    }
    else if(typeid(e) == typeid(Entier))
    {
        Entier& ecast = dynamic_cast<Entier &>(e);
        return *(new Reel(this->getX() * (float)ecast.getX()));
    }
    else if(typeid(e) == typeid(Expression))
    {
        Expression& ecast = dynamic_cast<Expression &>(e);
        return *(new Expression( this->toQString() + ' ' + ecast.getX() + ' * '));
    }
    else if(typeid(e) == typeid(Rationnel))
    {
        Rationnel& rcast = dynamic_cast<Rationnel &>(e);
        return *(new Reel(this->getX()*(rcast.getXAsFloat()/rcast.getYAsFloat())));
    }
    else if(typeid(e) == typeid(Reel))
    {
        Reel& rcast = dynamic_cast<Reel &>(e);
        return *(new Reel(this->getX()*rcast.getX()));
    }
    else{}
}
}
Litterale* OpMod::fonctionNum(Nombres *arg1, Litterale *arg2){
    Entier* n1 = dynamic_cast<Entier*>(arg1);
    Entier* n2 = dynamic_cast<Entier*>(arg2);
    if (n1 == nullptr || n2 == nullptr)
        throw ComputerException("Arguments invalides");

    int val = (int)n1->getValue()%(int)n2->getValue();
    Entier* res = new Entier(val);
    if (n1->getNeg() || n2->getNeg())
        res->setNeg(true);

    return res;
}
Element& Reel::operator/(Element& e)
{

    if(typeid(e) == typeid(Complexe))
    {
        Complexe& ecast = dynamic_cast<Complexe &>(e);

        if(typeid(*ecast.getRe()) == typeid(Entier))
        {
            Entier* ccast = dynamic_cast<Entier *>(ecast.getRe());
            Reel* tmp = new Reel(this->getX() / (float)ccast->getX());
            return *(new Complexe(tmp, ecast.getIm()->clone()));
        }
        else if(typeid(*ecast.getRe()) == typeid(Reel))
        {
            Reel* rcast = dynamic_cast<Reel *>(ecast.getRe());
            Reel* tmp = new Reel(this->getX() / rcast->getX());
            return *(new Complexe(tmp, ecast.getIm()->clone()));
        }
        else if(typeid(*ecast.getRe()) == typeid(Rationnel))
        {
            Rationnel* rcast = dynamic_cast<Rationnel *>(ecast.getRe());
            Reel* tmp = new Reel(this->getX()/((float)rcast->getX()/(float)rcast->getY()));
            return *(new Complexe(tmp, ecast.getIm()->clone()));
        }

    }
    else if(typeid(e) == typeid(Entier))
    {
        Entier& ecast = dynamic_cast<Entier &>(e);
        return *(new Reel(this->getX() / (float)ecast.getX()));
    }
    else if(typeid(e) == typeid(Expression))
    {
        Expression& ecast = dynamic_cast<Expression &>(e);
        return *(new Expression(this->toQString() + ' ' + ecast.getX() + ' / '));
    }
    else if(typeid(e) == typeid(Rationnel))
    {
        Rationnel& rcast = dynamic_cast<Rationnel &>(e);
        return *(new Reel(this->getX()/((float)rcast.getX()/(float)rcast.getY())));
    }
    else if(typeid(e) == typeid(Reel))
    {
        Reel& rcast = dynamic_cast<Reel &>(e);
        return *(new Reel(this->getX() / rcast.getX()));
    }
    else{qDebug()<<"erreur";}
}
Element* Calculateur::mean()
{
    Entier* e = dynamic_cast<Entier*>(this->pop());
    unsigned int i;
    for(i=0;i<e->getXAsInt()-1;i++)
    {
        this->addition();
    }
    Reel* div = new Reel(i+1);
    Element* sum = this->pop();
    Element* res = this->cast(&(sum->operator /(*div)));
    delete div;
    delete sum;
    this->push(res);
}
Element& Reel::operator+(Element& e)
{

    if(typeid(e) == typeid(Complexe)) //! Si l'element en argument est un complexe
    {
        Complexe& ecast = dynamic_cast<Complexe &>(e);

        if(typeid(*ecast.getRe()) == typeid(Entier*))
        {
            Entier* ccast = dynamic_cast<Entier *>(ecast.getRe());
            Reel* tmp = new Reel(ccast->getX()+ this->getXAsFloat());
            return *(new Complexe(tmp, ecast.getIm()->clone()));
        }
        else if(typeid(*ecast.getRe()) == typeid(Reel))
        {
            Reel* rcast = dynamic_cast<Reel *>(ecast.getRe());
            Reel* tmp = new Reel(rcast->getX() + this->getX());
            return *(new Complexe(tmp, ecast.getIm()->clone()));
        }
        else if(typeid(*ecast.getRe()) == typeid(Rationnel))
        {
            Rationnel* rcast = dynamic_cast<Rationnel *>(ecast.getRe());
            Reel* tmp = new Reel(((float)rcast->getX()/(float)rcast->getY()) + this->getX());
            return *(new Complexe(tmp, ecast.getIm()->clone()));
        }

    }
    else if(typeid(e) == typeid(Entier))
    {
        Entier& ecast = dynamic_cast<Entier &>(e);
        return *(new Reel((float)ecast.getX()+this->getX()));
    }
    else if(typeid(e) == typeid(Expression))
    {
        Expression& ecast = dynamic_cast<Expression &>(e);
        return *(new Expression( this->toQString() + ' ' + ecast.getX() + ' + '));
    }
    else if(typeid(e) == typeid(Rationnel))//! Si l'element en argument est un rationnel
    {
        Rationnel& rcast = dynamic_cast<Rationnel &>(e);
        return *(new Reel(((float)rcast.getX()/(float)rcast.getY())+this->getX()));
    }
    else if(typeid(e) == typeid(Reel)) //! Si l'element en argument est un reel
    {
        Reel& rcast = dynamic_cast<Reel &>(e);
        return *(new Reel(rcast.getX()+this->getX()));
    }
}
Element& Entier::operator-(Element& e)
{
     if(typeid(e) == typeid(Complexe))
    {
        Complexe& ecast = dynamic_cast<Complexe &>(e);

        if(typeid(ecast.getRe()) == typeid(Entier*))
        {
            Entier* ccast = dynamic_cast<Entier *>(ecast.getRe());
            Entier* tmp = new Entier(this->getX() - ccast->getX());
            return *(new Complexe(tmp, ecast.getIm()->clone()));
        }
        else if(typeid(ecast.getRe()) == typeid(Reel*))
        {
            Reel* rcast = dynamic_cast<Reel *>(ecast.getRe());
            Reel* tmp = new Reel((float) this->getX() - rcast->getX());
            return *(new Complexe(tmp, ecast.getIm()->clone()));
        }
        else if(typeid(ecast.getRe()) == typeid(Rationnel*))
        {
            Rationnel* rcast = dynamic_cast<Rationnel *>(ecast.getRe());
            Rationnel* tmp = new Rationnel(this->getX()*rcast->getY() - rcast->getX(), rcast->getY());
            return *(new Complexe(tmp, ecast.getIm()->clone()));
        }

    }
    else if(typeid(e) == typeid(Entier))
    {
        Entier& ecast = dynamic_cast<Entier &>(e);
        return *(new Entier(this->getX() - ecast.getX()));
    }
    else if(typeid(e) == typeid(Expression))
    {
        Expression& ecast = dynamic_cast<Expression &>(e);
        return *(new Expression( this->toQString() + ' ' + ecast.getX() + ' - '));
    }
    else if(typeid(e) == typeid(Rationnel))
    {
        Rationnel& rcast = dynamic_cast<Rationnel &>(e);
        return *(new Rationnel(this->getX()*rcast.getY() - rcast.getX(), rcast.getY()));
    }
    else if(typeid(e) == typeid(Reel))
    {
        Reel& rcast = dynamic_cast<Reel &>(e);
        return *(new Reel((float)this->getX() - rcast.getX()));
    }
}
Example #11
0
int simplifier(Entier a, Entier b){

    Entier& test = a.mod(b);

    if (test.getValue() == 0){
        return 1;
    } else return 0;
}
Element* Calculateur::mod()
{
    if(typeid(*this->pileC->top()) == typeid(Expression))
    {
        this->eval();
    }
    if(typeid(*this->pileC->top()) == typeid(Complexe))
    {   qDebug()<<"on est en complexe";
         throw std::logic_error( "mod : le premier parametre doit être une constante");
    }
    if(typeid(*this->pileC->top()) != typeid(Entier))
    {
         throw std::logic_error("Il faut que l'élément soit un entier");
    }
    if(typeid(*this->pileC->top()) == typeid(Entier))
    {   qDebug()<<"on est en entier";
        Entier* m = dynamic_cast<Entier*>(this->pileC->pop()); /*!< module */
        qDebug()<<"l'entier est"<<m->toQString();

        if(typeid(*this->pileC->top()) == typeid(Expression))
        { qDebug()<<"on est en expression";
            this->pileC->push(m);
            throw std::logic_error("Le deuxième élément est une expression");
        }
        if(typeid(*this->pileC->top()) == typeid(Complexe))
        {   qDebug()<<"on est en complexe";
            this->pileC->push(m);
             throw std::logic_error("Le deuxième élément est un complexe");
        }
        if(typeid(*this->pileC->top()) != typeid(Entier))
        {   qDebug()<<"on est en non entier";
             throw std::logic_error("Le deuxième élément n'est pas de type entier");
        }
        if(typeid(*this->pileC->top()) == typeid(Entier))
        {   qDebug()<<"on est en entier";
            Entier* e = dynamic_cast<Entier*>(this->pileC->pop());
            qDebug()<<e->toQString();
            Entier* tmp = new Entier(e->getXAsInt()%m->getXAsInt());
            qDebug()<<tmp->toQString();
            delete m;
            delete e;
            this->pileC->push(tmp);
            return tmp;
        }
        else
        {
             throw std::logic_error("Le deuxième élément n'est pas un élément valide");
        }
    }
    else
    {
         throw std::logic_error("Le premier élément n'est pas un élément valide");
    }
}
Example #13
0
Nombre& Entier::division(const Nombre& n) const {
    // Nombre -> Entier
    const Entier* ptEntier = dynamic_cast<const Entier*>(&n);
    if (ptEntier == 0) {
        // Nombre -> Reel
        const Reel* ptReel = dynamic_cast<const Reel*>(&n);
        if (ptReel == 0) {
            // Nombre -> Rationnel
            const Rationnel* ptRationnel = dynamic_cast<const Rationnel*>(&n);
            if (ptRationnel == 0) {
                throw CalculatriceException("Entier : division : Impossible d'effectuer le dynamic cast!");
            } else { //  Entier / Rationnel
                if (ptRationnel->getNum().getX()/ptRationnel->getDen().getX()==0) {
                    throw CalculatriceException("Entier : division : Division par 0");
                }
                Entier num = Entier(mX  * ptRationnel->getDen().getX());
                Entier den = Entier(ptRationnel->getNum().getX());
                Rationnel* res= new Rationnel(num.toEntier(), den.toEntier());
                res->simplifier();
                Nombre& ref = *res;
                return(ref);
            }
        } else { // Entier / Reel
            if (ptReel->getX()==0) {
                throw CalculatriceException("Entier : division : Division par 0");
            }
            Nombre& ref = this->division(ptReel->toRationnel());
            return(ref);
        }
    } else { // Entier / Entier
        if (ptEntier->getX()==0) {
            throw CalculatriceException("Entier : division : Division par 0");
        }
        Reel* res = new Reel(mX / ptEntier->getX());
        Nombre& ref = *res;
        return(ref);
    }
}
void CalculatriceModele::getSum(int type){
    if(pile.size()>=1){
        Constante* a = pile.pop();
        if(typeid (*a).name()==typeid (Entier).name()){
            Entier* e = dynamic_cast<Entier*>(a);
            int k = e->GetEntier();

            if(pile.size()>=k)
            {
                for(int i=0; i<k-1; i++){
                    emit getAdd(type);
                }

                Constante* res = pile.pop();
                pile.push(res);
                if(typeid (*res).name()==typeid (Expression).name()){
                    emit getExpression();
                }
            }
            else {
                logger1->Write(&LogMessage(ERROR,"pas assez d'expressions"));
                logger2->Write(&LogMessage(ERROR,"pas assez d'expressions"));
                pile.push(a);}
        }else{
            pile.push(a);
            logger1->Write(&LogMessage(ERROR,"type non conforme"));
            logger2->Write(&LogMessage(ERROR,"type non conforme"));
        }

        emit finOp(&pile);
    }
    else{
    logger1->Write(&LogMessage(ERROR,"taille pile insuffisante"));
    logger2->Write(&LogMessage(ERROR,"taille pile insuffisante"));
    }
}
void CommandeDivision::execute()throw(LogMessage){
    savePileAvtExe();
    Constante* c1;
    Constante* c2;
    try{
        c1 = _pileCourante->depiler();
        c2 = _pileCourante->depiler();

        if(typeid(*c1)==typeid(Expression) && typeid(*c2)==typeid(Expression)){
            throw LogMessage("addition(): impossible d'appliquer un operateur sur 2 expressions",1);
        }
        if (typeid(*c1)==typeid(Expression)){
            Expression* oldExpr=dynamic_cast<Expression*>(c1);
            QString oldChaine=oldExpr->getExp();
            QString newChaine;
            if(typeid(*c2)!=typeid(Complexe)){
                Nombre* nb=dynamic_cast<Nombre*>(c2);
                newChaine = nb->toQString();
            }
            else{
                Complexe* nb=dynamic_cast<Complexe*>(c2);
                newChaine = nb->toQString();
            }
            oldChaine.remove(oldChaine.length()-1,1);
            _pileCourante->empilerExpression(oldChaine.append(" "+newChaine+" "+'/'+'\''));
        }

        else if (typeid(*c2)==typeid(Expression)){
            Expression* oldExpr=dynamic_cast<Expression*>(c2);
            QString oldChaine=oldExpr->getExp();
            QString newChaine;
            if(typeid(*c1)!=typeid(Complexe)){
                Nombre* nb=dynamic_cast<Nombre*>(c1);
                newChaine = nb->toQString();
            }
            else{
                Complexe* nb=dynamic_cast<Complexe*>(c1);
                newChaine = nb->toQString();
            }
            oldChaine.remove(oldChaine.length()-1,1);
            _pileCourante->empilerExpression(oldChaine.append(" "+newChaine+" "+'/'+'\''));
        }

        else{

        if(_utilisateur->useComplexe()){
            Complexe *co1;
            Complexe *co2;

            if(typeid(*c1)==typeid(Complexe))
                co1 =dynamic_cast<Complexe*>(c1);
            else if(typeid(*c1)==typeid(Entier)){
                Entier* nb = dynamic_cast<Entier*>(c1);
                co1 = nb->toComplexe();
            }
            else if(typeid(*c1)==typeid(Rationnel)){
                Rationnel* nb = dynamic_cast<Rationnel*>(c1);
                co1 = nb->toComplexe();
            }
            else if(typeid(*c1)==typeid(Reel)){
                Reel* nb = dynamic_cast<Reel*>(c1);
                co1 = nb->toComplexe();
            }

            if(typeid(*c2)==typeid(Complexe))
                 co2 = dynamic_cast<Complexe*>(c2);
            else if(typeid(*c2)==typeid(Entier)){
                Entier* nb = dynamic_cast<Entier*>(c2);
                co2 = nb->toComplexe();
            }
            else if(typeid(*c2)==typeid(Rationnel)){
                Rationnel* nb = dynamic_cast<Rationnel*>(c2);
                co2 = nb->toComplexe();
                }
            else if(typeid(*c2)==typeid(Reel)){
                 Reel* nb = dynamic_cast<Reel*>(c2);
                 co2 = nb->toComplexe();
             }

            if(_utilisateur->useEntier()){
                co1->attrToEntier();
                co2->attrToEntier();
            }
            else if(_utilisateur->useRationnel()){
                co1->attrToRationnel();
                co2->attrToRationnel();
            }
            else if(_utilisateur->useReel()){
                co1->attrToReel();
                co2->attrToReel();
            }

            if(co1->getReel()==0 && co2->getImg()==0)
                throw LogMessage("division(): impossible de diviser par 0",1);
            else{
            Complexe * res = *(co1)/co2;
            _pileCourante->empilerConstante(res);
            savePileApresExe();
            }
        }

        else{
            if(typeid(*c1)==typeid(Complexe) || typeid(*c2)==typeid(Complexe))
                throw LogMessage("division(): impossible de convertir un complexe en un autre type de constante, cochez complexe",1);

            if(_utilisateur->useEntier()){
                Entier *e1;
                Entier *e2;
                int choix=QMessageBox::Ok;

                if(typeid(*c1)!=typeid(Expression)&& typeid(*c2)!=typeid(Expression)){
                    if(typeid(*c1)==typeid(Reel) || typeid(*c1)==typeid(Rationnel) || typeid(*c2)==typeid(Reel) || typeid(*c2)==typeid(Rationnel)){
                        choix=continuer();
                    }
                    if(choix==QMessageBox::Ok){
                        Nombre * n1 = dynamic_cast<Nombre*>(c1);
                        e1 = n1->toEntier();
                        Nombre * n2 = dynamic_cast<Nombre*>(c2);
                        e2 = n2->toEntier();

                        if (e2->getNb()==0)
                                throw LogMessage("division(): impossible de diviser par 0",1);
                        else{
                        Entier * res = *(e1)/e2;
                        _pileCourante->empilerConstante(res);
                        savePileApresExe();
                        }
                    }
                    else{
                        _pileCourante->empilerConstante(c2);
                        _pileCourante->empilerConstante(c1);
                    }
                }
                else{
                    _pileCourante->empilerConstante(c2);
                    _pileCourante->empilerConstante(c1);
                    throw LogMessage("division() : La constante doit être un nombre",1);
                }
            }

            else if(_utilisateur->useRationnel()){
                Rationnel *ra1;
                Rationnel *ra2;

                int choix=QMessageBox::Ok;

                if(typeid(*c1)!=typeid(Expression) && typeid(*c2)!=typeid(Expression)){
                    if(typeid(*c1)==typeid(Reel) || typeid(*c2)==typeid(Reel)){
                        choix=continuer();
                    }
                    if(choix==QMessageBox::Ok){
                    Nombre * n1 = dynamic_cast<Nombre*>(c1);
                    Nombre * n2 = dynamic_cast<Nombre*>(c2);
                    ra1 = n1->toRationnel();
                    ra2 = n2->toRationnel();
                }
                else{
                    _pileCourante->empilerConstante(c2);
                    _pileCourante->empilerConstante(c1);
                    throw LogMessage("division() : La constante doit être un nombre",1);
                }

                if(ra2->getNum()==0)
                    throw LogMessage("division(): impossible de diviser par 0",1);
                else{
                Rationnel * res = *(ra1)/ra2;
                _pileCourante->empilerConstante(res);
                savePileApresExe();
                }
                }
            }

            else if(_utilisateur->useReel()){
                Reel *re1;
                Reel *re2;

                int choix=QMessageBox::Ok;

                if(typeid(*c1)!=typeid(Expression) && typeid(*c2)!=typeid(Expression)){
                    if(typeid(*c1)==typeid(Rationnel) || typeid(*c2)==typeid(Rationnel)){
                        choix=continuer();
                    }
                    if(choix==QMessageBox::Ok){
                    Nombre * n1 = dynamic_cast<Nombre*>(c1);
                    Nombre * n2 = dynamic_cast<Nombre*>(c2);
                    re1 = n1->toReel();
                    re2 = n2->toReel();
                }
                else{
                    _pileCourante->empilerConstante(c2);
                    _pileCourante->empilerConstante(c1);
                    throw LogMessage("division() : La constante doit être un nombre",1);
                }

                if(re2->getReel()==0)
                    throw LogMessage("division(): impossible de diviser par 0",1);
                else{
                Reel * res = *(re1)/re2;
                _pileCourante->empilerConstante(res);
                savePileApresExe();
                }
            }
            }
            else{
                _pileCourante->empilerConstante(c2);
                _pileCourante->empilerConstante(c1);
                throw LogMessage("Type utilisé non reconnu",1);
            }
        }
    }
    }
    catch(LogMessage msg){
        //La pile ne contenait pas au moins 2 éléments
        if(c2!=0)
            _pileCourante->empilerConstante(c2);
        if(c1!=0)
            _pileCourante->empilerConstante(c1);
        throw;
    }
}
Example #16
0
Entier Entier::mod(Entier e){return n%e.GetEntier();}
Example #17
0
Entier::Entier(const Entier &e)
{
    this->value = e.getValue();
}
Example #18
0
Entier operator+(Entier& a,  Entier& b){

    double valeur=a.getVal()+b.getVal();
    Entier res(valeur);
    return res;
}
Element* Calculateur::pow()
{
    if(typeid(*this->pileC->top()) == typeid(Expression))
    {
        this->eval();
    }
    if(typeid(*this->pileC->top()) == typeid(Complexe))
    {
         throw std::logic_error("Le premier élément ne peut pas être un complexe");
    }
    else if(typeid(*this->pileC->top())== typeid(Entier))
    {
        Entier* e = dynamic_cast<Entier*>(this->pileC->pop());

        if(typeid(*this->pileC->top()) == typeid(Expression))
        {
            Element* tmp = this->eval();
        }

        else if(typeid(*this->pileC->top())== typeid(Entier) || typeid(*this->pileC->top())== typeid(Rationnel))
        {
            Constante* c = dynamic_cast<Constante*>(this->pileC->pop());

            if(e->getXAsInt()>= 0)
            {
                Rationnel* tmp = new Rationnel(::pow(c->getXAsInt(),e->getXAsInt()),::pow(c->getYAsInt(),e->getXAsInt()));
                qDebug()<<tmp->toQString();
                Element* res = this->cast(tmp);
                delete e;
                delete c;
                delete tmp;
                this->pileC->push(res);
            }
            else
            {
                Reel* tmp = new Reel(::pow(c->getXAsFloat()/c->getYAsFloat(),e->getXAsInt()));

                Element* res = this->cast(tmp);
                delete e;
                delete c;
                delete tmp;
                this->pileC->push(res);
            }
        }
        else if(typeid(*this->pileC->top()) == typeid(Reel))
        {
            Constante* c = dynamic_cast<Constante*>(this->pileC->pop());
            Reel* tmp = new Reel(::pow(c->getXAsFloat(),e->getXAsFloat()));
            Element* res = this->cast(tmp);
            delete e;
            delete c;
            delete tmp;
            this->pileC->push(res);

        }
        else
        {
         throw std::logic_error("L'élément n'est pas un type connu");
        }
    }
    else if(typeid(*this->pileC->top()) == typeid(Reel) || typeid(*this->pileC->top()) == typeid(Rationnel))
    {
        Constante* p = dynamic_cast<Constante*>(this->pileC->pop());

        if((typeid(*this->pileC->top()) == typeid(Entier))||(typeid(*this->pileC->top()) == typeid(Rationnel)) || typeid(*this->pileC->top()) == typeid(Reel))
        {
            Constante* c = dynamic_cast<Constante*>(this->pileC->pop());
            Reel* tmp = new Reel(::pow(c->getXAsFloat()/c->getYAsFloat(),p->getXAsFloat()/p->getYAsFloat()));
            Element* res = this->cast(tmp);
            delete p;
            delete c;
            delete tmp;
            this->pileC->push(res);
            return res;

        }
        else
        {
           throw std::logic_error("Le deuxième élément n'est pas un type valide");
        }
    }
    else
    {
     throw std::logic_error("Le premier élément n'est pas un élément valide");
    }

}
Example #20
0
Entier operator*( Entier& a,  Entier& b){

    double val=a.getVal()*b.getVal();
    Entier res(val);
    return res;
}
Example #21
0
Entier operator/( Entier& a,  Entier& b){

    unsigned int val=a.getVal()/b.getVal();
    Entier res(val);
    return res;
}
Example #22
0
File: reel.cpp Project: Maerig/LO21
Reel::Reel(Entier e){

    val=e.getVal();
}
Example #23
0
Entier operator%( Entier& a,  Entier& b){
    double val=(int)a.getVal()%(int)b.getVal();
    Entier res(val);
    return res;
}
Example #24
0
LitteraleCalculable& Entier::mult(const LitteraleCalculable& l) const{
    const Entier* ptEntier = dynamic_cast<const Entier*>(&l);

    if (ptEntier != 0){
        // Entier * Entier
        Entier* res = new Entier(value * ptEntier->getValue());
        LitteraleCalculable& ref = *res;
        return ref;
    }
    else{
        const Rationnel* ptRationnel = dynamic_cast<const Rationnel*>(&l);

        if (ptRationnel!= 0){
            // Entier * Rationnel
            Entier num = (value * ptRationnel->getNum().getValue());
            Entier den = (ptRationnel->getDen().getValue());

            int type = simplifier(num, den);

            if (type == 0){
                Rationnel* res = new Rationnel(num,den);

                LitteraleCalculable& ref = *res;
                return ref;
            }
            if (type == 1) {
                Entier v = num.div(den);
                Entier* res = new Entier(v.getValue());
                LitteraleCalculable& ref = *res;//spl->simplifier(res);
                return ref;
            }
        }
        else {
            const Reel* ptReel = dynamic_cast<const Reel*>(&l);
            if (ptReel!=0){
                // Entier * Reel
                Reel* res= new Reel(value * ptReel->getValue());
                LitteraleCalculable& ref = *res;
                return ref;
            }else{
                const Expression* ptExpression=dynamic_cast<const Expression*>(&l);
                if (ptExpression!=0){
                        // Entier * Expression
                        LitteraleCalculable& ref = ptExpression->mult(*this);
                        return ref;
                   }else{
                    const Complexe* ptComplexe = dynamic_cast<const Complexe*>(&l);
                    if (ptComplexe!=0){
                            // Entier * Complexe
                            LitteraleCalculable& ref = ptComplexe->mult(*this);
                            return ref;
                    }
                }
            }
        }
    }
    throw CalcException("le type de l'argument 2 n'est pas reconnu");
    Entier* res = new Entier();
    LitteraleCalculable& ref = *res;
    return ref;
}
Example #25
0
/*!
  * \fn Entier(const Entier& e)
  * \brief Constructeur de copie
  * Constructeur de la classe Entier à partir d'un Entier existant déjà
  * \param e : référence sur un Entier existant
  */
Entier::Entier(const Entier& e):Constante(ENTIER)
{
    this->_entier=e.getEntier();
    this->_type = ENTIER;
}