Question: //This Program has to be done in C++. Please stricly follow the instructions. Thank You. //The contents of Additional resource for assignment (testPolynomial.cpp) / Given
//This Program has to be done in C++. Please stricly follow the instructions. Thank You.
//The contents of Additional resource for assignment (testPolynomial.cpp) / Given file is as follows (Opened through text-edit) :
#include "polynomial.h"
#include
#include
using namespace std;
void doNothing(Polynomial temp) {}
int main() {
//test constructor
Polynomial p1({17});
Polynomial p2({1, 2});
Polynomial p3({-1, 5});
Polynomial p4({5, 4, 3, 2, 1});
cout
cout
cout
cout
cout
cout
cout
//test copy constructor - the statement below uses the copy constructor
//to initialize poly3 with the same values as poly4
Polynomial p5(p4);
p5 += p3;
cout
cout
cout
cout
doNothing(p5);
cout
//tests the assignment operator
Polynomial p6;
cout
cout
cout
p6 = p4;
cout
cout
cout
//test the evaluaton
int x = 5;
cout
cout
Polynomial p7({3, 2, 1}); // 3x^2 + 2x + 1
cout
cout
cout
cout
cout
}
Problem You will implement a class Polynomial for storing and manipulating polynomial expressions. A polynomial is an expression of the form The number k is called the degree of the polynomial and the numbers a,.. ax are called the coefficients. Store each polynomial as a degree and a singly linked list of its coefficients, but 'backwards, i.e. with the lowest degree coefficient first. (Backwards makes your program easier) For example, the polynomial 4x3 ++7 would be stored as: head-ptr--> 7--> 1--> 0--> 4 degree: 3 Here the constant term, 7, is first, then the linear (x) term, 1, then the quadratic (2) term, 0, and finally the highest degree term with a coefficient of 4. In addition, the degree of the polynomial, 3, is stored in the member variable degree. Storing the polynomials in this order, rather than in the order in which we normally write them, will make it easier to perform arithmetic operations. The class invariant (i.e, the thing that must be true about the class whenever a member function is finished making changes) is: 1. The coefficients are stored in a linked list with the constant term at the front of the ist and the highest order term at the end of the list 2. The zero polynomial is represented by a list with a single item, zero. The degree of the zero polynomial is 0. 3The list for a non-zero polynomial does not end with a zero coefficient. (in other words, the highest degree coefficient is only zero if this is the zero polynomial.) 4. The value of the degree member variable is one less than the length of the list. What you have to handle: . constructor that takes a vector of its coefficients in order from highest degree term to lowest copy control, Le. destructor, copy constructor and assignment operator . e
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
