Beispiel #1
0
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;
} 
Beispiel #2
0
FactorsMap::FactorsMap(const Polynomial &P) : QMap <QString, int>(), mConstant (1)
{
    this->insert(P.toString(), 1);
}
Beispiel #3
0
void FactorsMap::addPolynomial (const Polynomial &P)
{
    qDebug() << "Received:" << P.toString();
    (*this)[P.toString()] ++;
}