Question
The Polynom.h file: // IMPORTANT: Do not modify the contents of this file // // Polynom.h // A simple ploynomial class of degree n #ifndef
The Polynom.h file:
// 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
// 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
// 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
// Get the coefficient of x^k // Precondition: k >= 0 and k
// Stream insertion // Postcondition: Write the polynomial onto stream ostr. ostream& insert(ostream& ostr);
private: vector
};
// overloaded stream to write the polynomial RHS onto stream Out ostream& operator
The Ploynom.cc file:
#include "Polynom.h" #include
Polynom::Polynom(){
// implementation needed }
Polynom::Polynom(const vector
// implementation needed }
const Polynom& Polynom::operator+(const Polynom& RHS) const {
// implementation needed }
const Polynom& Polynom::operator-(const Polynom& RHS) const {
// implementation needed }
double Polynom::operator()(double x) const{
// implementation needed }
ostream& operator
// implementation needed }
bool Polynom::setCoeff(int k, int c) { // implementation needed }
bool Polynom::getCoeff(int k, int& c) {
// implementation needed }
ostream& Polynom::insert(ostream& ostr) {
// implementation needed
In this assignment you will 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 (z) = anr" + an-11n-1 + + all + ao The highest power of variable r that occurs in the polynomial in this case n) is called the degree of the polynomial. The quantities a,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(r), q(z) =2+51 + 6 for for r-2, by writing the polynomial in the following form, q(z) = ((z + 5)| + 6) and then substituting2 to obtain, q(2)-((2 + 5)2+ 6)-((7)2 + 6)-(14 + 6)-20 We can add two polynomials and subtract one from the other. Examples are shown below Plz)3x3 + 212 +1 + 16, q(z) =12 +51 +6 3rs + 312 + 6+22 p(z) + q(z) = (3 + 0)z? + (2 + 1)z? + (1 + 5)I + (16 + 6) p(x) q() (3-0)(2 1)2 (1 5)r(16-3r3(-4)r 10 = 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 21 16, 5 6 It is possible that some of the coefficients in a polynomial are 0. Consider the polynomial r(x) 5r92r19 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 The definition of a polynomial class is provided in the file Polynom.h and a skeleton im- plementation is provided in the file Polynom.cc. This assignment asks you to implement the functions that appear in Polynom.cc according to the specification provided in Polynom.h and the description given above What to submit 1. The completed implementation of class Polynom in files Polynom.h and Polynom.cc 2. A test program in a file named test-polynom.cc to thoroughly test the member functions of the class Polynom. In this assignment you will 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 (z) = anr" + an-11n-1 + + all + ao The highest power of variable r that occurs in the polynomial in this case n) is called the degree of the polynomial. The quantities a,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(r), q(z) =2+51 + 6 for for r-2, by writing the polynomial in the following form, q(z) = ((z + 5)| + 6) and then substituting2 to obtain, q(2)-((2 + 5)2+ 6)-((7)2 + 6)-(14 + 6)-20 We can add two polynomials and subtract one from the other. Examples are shown below Plz)3x3 + 212 +1 + 16, q(z) =12 +51 +6 3rs + 312 + 6+22 p(z) + q(z) = (3 + 0)z? + (2 + 1)z? + (1 + 5)I + (16 + 6) p(x) q() (3-0)(2 1)2 (1 5)r(16-3r3(-4)r 10 = 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 21 16, 5 6 It is possible that some of the coefficients in a polynomial are 0. Consider the polynomial r(x) 5r92r19 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 The definition of a polynomial class is provided in the file Polynom.h and a skeleton im- plementation is provided in the file Polynom.cc. This assignment asks you to implement the functions that appear in Polynom.cc according to the specification provided in Polynom.h and the description given above What to submit 1. The completed implementation of class Polynom in files Polynom.h and Polynom.cc 2. A test program in a file named test-polynom.cc to thoroughly test the member functions of the class PolynomStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started