本文整理汇总了C++中Poly::getCoeff方法的典型用法代码示例。如果您正苦于以下问题:C++ Poly::getCoeff方法的具体用法?C++ Poly::getCoeff怎么用?C++ Poly::getCoeff使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poly
的用法示例。
在下文中一共展示了Poly::getCoeff方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: multiply
Poly* Poly::multiply(Poly* other)
{
double TOL = .00001;
int n = getDegree();
int m = other->getDegree();
Poly* temp = new Poly(n + m);
for (int i = 0; i <= n; i++) //loop over coeffs
{
for (int j = 0; j <= m; j++) //loop over second coeffs
{
double coeff_i = getCoeff(i);
double coeff_j = other->getCoeff(j);
if (fabs(coeff_i) > TOL && fabs(coeff_j) > TOL)
{
int power = i + j;
double coeff = temp->getCoeff(power);
temp->setCoeff(power, coeff + (coeff_i * coeff_j));
}
}
}
return temp;
}
示例2: main
int main() {
Poly count[8];
cout << "Constructors" << endl;
count[0] = Poly();
count[1] = Poly(1);
count[2] = Poly(0);
count[3] = Poly(-1);
count[4] = Poly(0, 1);
count[5] = Poly(1, 1);
count[6] = Poly(-1, 1);
count[7] = Poly(1, -1);
for (int i = 0; i < 8; i++) {
cout << count[i] << endl;
}
cout << "add" << endl;
count[0].setCoeff(2,2);
count[0].setCoeff(4,4);
count[0].setCoeff(3,3);
count[2].setCoeff(2,2);
count[2].setCoeff(4,4);
count[2].setCoeff(3,3);
cout << count[0] << endl;
cout << count[2] << endl;
Poly p = count[0] + count[2];
cout << p << endl;
p = p - count[0] - count[2];
cout << p << endl;
p = p - count[0];
cout << p << endl;
p.setCoeff(-1,-1);
cout << p.getCoeff(-2) << endl;
return 0;
}