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


C++ Polynomial::toString方法代码示例

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


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

示例1: runMenu

int runMenu(Polynomial& lhs, Polynomial& rhs, Polynomial& ans) {
    //prompt
    cout << "How would you like to add Polynomials?" << endl
         << "    1. Do the whole shebang!" << endl
         << "    2. Enter first Polynomial." << endl
         << "    3. Enter second Polynomial." << endl
         << "    4. View current Polynomials." << endl
         << "    5. Compute!" << endl
         << "    6. Quit." << endl
         << ": ";
    
    string input;
    bool error = false;
    
    cin >> input;
    
    switch (strtol(input.c_str(),NULL,10)) { //protects from cin >> int not getting an int and throwing a tantrum
        case 1: //enter two polynomials, compute, and view, without going back to the menu
            error = inputPoly(lhs);
            if (error) break;
            error = inputPoly(rhs);
            if (error) break;
            ans = lhs + rhs;
            lhs.reduce();
            rhs.reduce();
            cout << "\n\n" << lhs.toString() << endl
                 << "+\n" << rhs.toString() << endl
                 << "=\n" << ans.toString() << endl << endl; 
            break;
        case 2: //input left operand
            error = inputPoly(lhs);
            lhs.reduce();
            break;
        case 3: //input right operand
            error = inputPoly(rhs);
            rhs.reduce();
            break;
        case 4: //view stored polynomials without adding
            cout << lhs.toString() << endl << endl
                 << rhs.toString() << endl << endl
                 << ans.toString() << endl << endl;
            break;
        case 5: //add two polynomials and display the resulting equation
            ans = lhs + rhs;
            cout << "\n\n" << lhs.toString() << endl
                 << "+\n" << rhs.toString() << endl
                 << "=\n" << ans.toString() << endl << endl; 
            break;
        case 6: //end program
            cout << "See ya!" << endl; //only viewable if your terminal doesn't automatically close
            return 0;
            break;
        default: //unexpected input
            cout << "Invalid selection" << endl;
    }
    if (error) cout << "\nError parsing string!" << endl;
    return 1;
} 
开发者ID:jmbp77umkc,项目名称:CS303_P1B,代码行数:58,代码来源:main.cpp

示例2: mConstant

FactorsMap::FactorsMap(const Polynomial &P) : QMap <QString, int>(), mConstant (1)
{
    this->insert(P.toString(), 1);
}
开发者ID:alartum,项目名称:polynomial,代码行数:4,代码来源:factorsmap.cpp

示例3: addPolynomial

void FactorsMap::addPolynomial (const Polynomial &P)
{
    qDebug() << "Received:" << P.toString();
    (*this)[P.toString()] ++;
}
开发者ID:alartum,项目名称:polynomial,代码行数:5,代码来源:factorsmap.cpp


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