Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

void Polynomial::normalize ( ) { if ( degree < 0 ) { terms.clear ( ) ; return; } std::list::iterator it = terms.begin ( ) ;

void Polynomial::normalize ()
{
if (degree <0)
{
terms.clear();
return;
}
std::list::iterator it = terms.begin();
while (it != terms.end())
{
if (it->coefficient ==0)
it = terms.erase(it);
else
++it;
}
if (terms.begin()!= terms.end())
degree = terms.back().power;
else
degree =0;
}
Polynomial::Polynomial ()
: degree(-1), coefficients(nullptr)
{
}
Polynomial::Polynomial (int b, int a)
: degree(1), coefficients(new int[2])
{
coefficients[0]= b;
coefficients[1]= a;
normalize();
}
Polynomial::Polynomial (Term term)
: degree(term.power), coefficients(new int[term.power+1])
{
for (int i =0; i < degree; ++i)
coefficients[i]=0;
coefficients[degree]= term.coefficient;
normalize();
}
Polynomial::Polynomial (int nC, int coeff[])
: degree(nC-1), coefficients(new int[nC])
{
for (int i =0; i <= degree; ++i)
coefficients[i]= coeff[i];
normalize();
}
void Polynomial::normalize ()
{
while (degree+1>1 && coefficients[degree]==0)
--degree;
}
int Polynomial::getDegree() const
{
return degree;
}
int Polynomial::getCoeff(int power) const
{
if (power >=0 && power <= degree)
{

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Eric Redmond ,Jim Wilson

1st Edition

1934356921, 978-1934356920

Students also viewed these Databases questions

Question

AIM: Write C program for sorting using a pointer.

Answered: 1 week ago

Question

6. How do histories influence the process of identity formation?

Answered: 1 week ago