Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is the file that needs implementing: // IMPORTANT: Do not modify the conten

ID: 3602895 • Letter: H

Question

Here is the file that needs implementing:

// IMPORTANT: Do not modify the contents of this file   
// Polynom.h
// A simple ploynomial class of degree n
#ifndef POLYNOM_H
#define POLYNOM_H
#include
#include
using namespace std;
class Polynom {
public:
// Postcondition: Creates an "empty" polynomial
Polynom();

// Postcondition: Creates a polynomial with coefficients provided in the vector parameter;   
// the degree of the polynomial is the size of the vector plus 1
Polynom(const vector& coeff);

// Basic arithmetic operations:
// Operator +
// Postcondition: The sum of this polynomial and RHS is returned; this   
// and RHS are unchanged   
const Polynom& operator+(const Polynom& RHS) const;

// Operator -
// Postcondition: The RHS is subtracted from this and the result is returned; this   
// and RHS are unchanged   
const Polynom& operator-(const Polynom& RHS) const;

// Evaluation;   
// Operator ()   
// Postcondition: this polynomial is evaluated at x and the the value
// is returned; this polynomial is unchanged
double operator()(double x) const;

// Set the coefficient of x^k
// Precondition: k >= 0 and k <= n, where n is the degree of this polynomial   
// Postcondition: If precondition is met, then coefficient of x^k is changed to
// c and returns true; otherwise no change is made and returns false;   
bool setCoeff(int k, int c);

// Get the coefficient of x^k
// Precondition: k >= 0 and k <= n, where n is the degree of this polynomial   
// Postcondition: If precondition is met, then the function assigns the
// coefficient of x^k in parameter c and return true;
// otherwise returns false and parameter c remains unchanged
bool getCoeff(int k, int& c);

// Stream insertion   
// Postcondition: Write the polynomial onto stream ostr.
ostream& insert(ostream& ostr);

private:
vector P; // coefficients of the polynomial; P[i] is the coefficient
// of x raised to power i;   

};

// overloaded stream to write the polynomial RHS onto stream Out
ostream& operator<<(ostream& Out, const Polynom& RHS);
#endif

Note: Only implement what specified/required above. Do not add extra/new functions.

In this assignment you wl define, implement, and test a C class called Polynom to represent and use polynomials A polynomial function of independent variable r can be written as The highest power of variable r that occurs in the polynomial (in this case n) is called the degree of the polynoial. The quantities an, ao are constants known as coefficients. In this assignment coefficients are int type and can be positive, negative, or 0 A basic operation for polynomials is to evaluate a polynomial at a specific value of r. For example, we can evaluate the quadratic polynomial q(), q(z) =12 + 51 + 6 for for = 2, by writing the polynomial in the following form. q(z) = ((z + 5)| + 6) and then substituting r = 2 to obtain, g(2) = ((2 + 5)2 + 6) = ((72 + 6)-(14 + 6)-20 We can add two polynomials and subtract one from the other. Examples are shown below p(z) + q(z) = (3 + 0)r' + (2 + 1)z? + (1 +5)| + (16+6) 33 + 312 + 6x+ 22 = A simple way to represent a polynomial object of degree n is to use a vector of length n+1 to store the coefficients. For example, the polynomials p and q can be represented by vectors of length 4 and 3, respectively p 3 2 1 16, q 1 5 6] It is possible that some of the coefficients in a polynomial are 0. Consider the polynomial r(r) 5? + 24 + 19 where the largest power of r is 9 so that we need a vector of length 10 to store the polynomial r 5 0 0 0 0 2 0 0 0 6 This assignment asks you to implement the functions that appear in Polynom.cc according to the specification provided in the description given above.

Explanation / Answer

// IMPORTANT: Do not modify the contents of this file   
// Polynom.h
// A simple ploynomial class of degree n
#ifndef POLYNOM_H
#define POLYNOM_H
#include
#include
using namespace std;
class Polynom {
public:
// Postcondition: Creates an "empty" polynomial
Polynom();

// Postcondition: Creates a polynomial with coefficients provided in the vector parameter;   
// the degree of the polynomial is the size of the vector plus 1
Polynom(const vector& coeff);

// Basic arithmetic operations:
// Operator +
// Postcondition: The sum of this polynomial and RHS is returned; this   
// and RHS are unchanged   
const Polynom& operator+(const Polynom& RHS) const;

// Operator -
// Postcondition: The RHS is subtracted from this and the result is returned; this   
// and RHS are unchanged   
const Polynom& operator-(const Polynom& RHS) const;

// Evaluation;   
// Operator ()   
// Postcondition: this polynomial is evaluated at x and the the value
// is returned; this polynomial is unchanged
double operator()(double x) const;

// Set the coefficient of x^k
// Precondition: k >= 0 and k <= n, where n is the degree of this polynomial   
// Postcondition: If precondition is met, then coefficient of x^k is changed to
// c and returns true; otherwise no change is made and returns false;   
bool setCoeff(int k, int c);

// Get the coefficient of x^k
// Precondition: k >= 0 and k <= n, where n is the degree of this polynomial   
// Postcondition: If precondition is met, then the function assigns the
// coefficient of x^k in parameter c and return true;
// otherwise returns false and parameter c remains unchanged
bool getCoeff(int k, int& c);

// Stream insertion   
// Postcondition: Write the polynomial onto stream ostr.
ostream& insert(ostream& ostr);

private:
vector P; // coefficients of the polynomial; P[i] is the coefficient
// of x raised to power i;   

};

// overloaded stream to write the polynomial RHS onto stream Out
ostream& operator<<(ostream& Out, const Polynom& RHS);
#endif