Question
// I just need the copy-control part solved of this problem.. This part of the program has to be done in C++ and strictly follow
// I just need the copy-control part solved of this problem.. This part of the program has to be done in C++ and strictly follow the instructions, and work with the code given in the main().. The additional resource given in this assignment ()only has the main(testpolynomial.cpp) which I am giving after the problem (opened through text-edit).. Thanks in advance
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
//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
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