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


C++ Poly::getCoeff方法代码示例

本文整理汇总了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;
}
开发者ID:castringer42,项目名称:Lab3,代码行数:26,代码来源:Poly.cpp

示例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;
}
开发者ID:jamesus95,项目名称:Cpp,代码行数:46,代码来源:test.cpp


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