本文整理汇总了C++中Polynomial::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ Polynomial::insert方法的具体用法?C++ Polynomial::insert怎么用?C++ Polynomial::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polynomial
的用法示例。
在下文中一共展示了Polynomial::insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readpoly
//Read a polynomial from an inputstream
void Helper::readpoly(std::ifstream& ifs, Polynomial& poly)
{
char c;
while(ifs>>c)
{
int iCoefficient = 0, iExponent = 0;
ifs>>iCoefficient>>c>>iExponent;
ifs>>c;
if(iExponent == 0 && iCoefficient == 0)
return;
else
poly.insert(iCoefficient, iExponent);
}
}
示例2:
/* Multiplication: multiplies two polynomials
For each term in second polynomial, copies
the first polynomial and multiplies each of
its terms by the second's term and inserts
the results into the output polynomial.
*/
Polynomial operator*(const Polynomial p){
Polynomial output;
Term* currentA = head;
/* for each term in A */
while (currentA->next)
{
/* for each term in B, multiply against
A's term and insert into output*/
Term* currentB = p.head;
while (currentB->next)
{
output.insert(*currentA->next * *currentB->next);
currentB = currentB->next;
}
currentA = currentA->next;
}
return output;
}
示例3: main
int main()
{
ifstream myFile("dataPoly.txt");
string currC;
string currE;
string currL;
double currCoeff;
int currExpon;
int x = 0,y,z,pNum;
string numPoly;
Polynomial* polyArray[12];
for(int i = 0; i < 12; i++)
{
Polynomial* polyList = new Polynomial;
polyArray[i] = polyList;
}
///////////////////////////////////////////////////////////////////////////////////////////
if (myFile.is_open())
{
myFile >> numPoly;
pNum = atoi(numPoly.c_str());
for(int i = 0; i < pNum;i++)
{
Polynomial* polyList = polyArray[i];
myFile >> currC;
myFile >> currE;
currCoeff = atof(currC.c_str());
currExpon = atoi(currE.c_str());
polyList->insert(currCoeff,currExpon,polyArray[10]);
while(currExpon != 0)
{
myFile >> currC;
myFile >> currE;
currCoeff = atof(currC.c_str());
currExpon = atoi(currE.c_str());
polyList->insert(currCoeff,currExpon,polyArray[10]);
}
polyArray[x] = polyList;
x++;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
while(currL.compare("Q") != 0 && myFile >> currL)
{
if (currL.compare("R") == 0)
{
myFile >> currL;
int x = atoi(currL.c_str()) - 1;
polyArray[10]->remove(polyArray[x]);
Polynomial* polyList = polyArray[x];
myFile >> currC;
myFile >> currE;
currCoeff = atof(currC.c_str());
currExpon = atoi(currE.c_str());
polyList->insert(currCoeff,currExpon,polyArray[10]);
while(currExpon != 0)
{
myFile >> currC;
myFile >> currE;
currCoeff = atof(currC.c_str());
currExpon = atoi(currE.c_str());
polyList->insert(currCoeff,currExpon,polyArray[10]);
}
}
else if(currL.compare("A") == 0)