当前位置: 首页>>代码示例>>C++>>正文


C++ Number::getReal方法代码示例

本文整理汇总了C++中Number::getReal方法的典型用法代码示例。如果您正苦于以下问题:C++ Number::getReal方法的具体用法?C++ Number::getReal怎么用?C++ Number::getReal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Number的用法示例。


在下文中一共展示了Number::getReal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
    Operation *p = Factory::createSubstractOperation("2-3");
    p->setLeft(Factory::createIntegerNumber(2));
    p->setRight(Factory::createIntegerNumber(3));

    cout << p->eval(NULL)->getInteger() << endl;

    GlobalContext::getInstance()->addNewLocalContest();
    GlobalContext::getInstance()->addNewVariableInLastContext("n", Factory::createIntegerNumber(5));

    cout << GlobalContext::getInstance()->isContaining("n") << endl;
    cout << GlobalContext::getInstance()->getNumber("n")->toString() << endl;

    Number *n = Factory::createNumber("2.5");
    cout << n->getInteger() << endl;
    cout << n->getReal() << endl;
    cout << n->toString() << endl;
    cout << n->isReal() << endl;

    GlobalContext::getInstance()->deleteLastLocalContext();

    //// fact
    Function *fact = Factory::createNewFunction("", "fact");
    list<string> *args = new list<string>();
    args->push_back("n");
    fact->setArgsNames(args);
    IfThenElse *ifthen = (IfThenElse*)Factory::createNewIf("if...");
    fact->setExpression(ifthen);
    BinaryNumberCondition *bc = Factory::createNewLessThanOrEqual("n<=0");
    Variable *v = Factory::createNewVariable("n");
    v->setName("n");
    bc->setLeft(v);
    bc->setRight(Factory::createIntegerNumber(0));
    ifthen->setBoolCondition(bc);

    // if true
    ifthen->setLeft(Factory::createIntegerNumber(1));
    // if false
    Operation *time = Factory::createTimeOperation("n*fact(n-1)");
    ifthen->setRight(time);
    time->setLeft(v);
    Operation *sub = Factory::createSubstractOperation("n-1");
    sub->setLeft(v);
    sub->setRight(Factory::createIntegerNumber(1));

    list<Expression*> *rec = new list<Expression*>();
    rec->push_back(sub);
    time->setRight(fact, rec);

//time->setRight(Factory::createIntegerNumber(5));

    cout.flush();

    list<Expression*> *ar = new list<Expression*>();
    ar->push_back(Factory::createIntegerNumber(3));
    cout << "Fact(3)=" << fact->eval(ar)->getInteger() << endl;

    return 0;
}
开发者ID:Diatirios,项目名称:CLTP1,代码行数:60,代码来源:main.cpp


注:本文中的Number::getReal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。