本文整理汇总了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;
}
示例2: mConstant
FactorsMap::FactorsMap(const Polynomial &P) : QMap <QString, int>(), mConstant (1)
{
this->insert(P.toString(), 1);
}
示例3: addPolynomial
void FactorsMap::addPolynomial (const Polynomial &P)
{
qDebug() << "Received:" << P.toString();
(*this)[P.toString()] ++;
}