📄 polymult.cpp
字号:
#include <iostream>
using namespace std;
#include "poly.h"
Poly MonoMult(const Poly& mono, const Poly& rhs)
// pre: mono is a single term (monomial)
// post: return mono*rhs
// if mono is a polynomial, returns mono.Head()*rhs
{
if (rhs.IsPoly())
{ return Poly(mono.leadingCoeff()*rhs.leadingCoeff(),
mono.degree() + rhs.degree()) + MonoMult(mono,rhs.Tail());
}
return Poly::ZERO; // base case accumulated properly
}
int main()
{
Poly p1,p2,p3,p4;
double x;
cout << "value of x ";
cin >> x;
p1 = Poly(3,2) + Poly(4,1) + Poly(-3,0);
p2 = Poly(4,2) + Poly(3,1) + Poly(2,0);
p3 = Poly(5,3);
cout << "p1 at " << x << ", " << p1.at(x) << "\t : " << p1 << endl;
cout << "p2 at " << x << ", " << p2.at(x) << "\t : " << p2<< endl;
cout << "p3 at " << x << ", " << p3.at(x) << "\t : " << p3 << endl;
p4 = MonoMult(p3,p1);
cout << "p4 at " << x << ", " << p4.at(x) << "\t : " << p4 << endl;
cout << "5p4 at " << x << ", " << (5*p4).at(x) << "\t : " << 5*p4 << endl;
cout << "total # terms used = " << Poly::TermsAllocated() << endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -