The purpose of this Assignment is to be familiar with classes, Files and overloaded operators. The class you will be working on defines one-variable polynomials (i.e 2x3+5x+4), and you will deal with arithmetic operators, including addition + and subtraction -
So you need to implement a C++ class called poly for polynomials, with the following specifications:
1. The class constructor, which initializes the polynomial variables degree and coefficients.
2. The method eval () for evaluating the polynomial based on the input value
3. The method print() for printing out the polynomial, which should follow the format below:(for example 1+ 2x^1+3x^2-7x^3…)
4. Overload the + operator for polynomial addition (x3 + x2 + 1) + (x4 + 3 x2 −2) = (x4 + x3 + 5x2 −1)
5. Overload the - operator for polynomial subtraction
6. Overload the <<(Insertion) and >>(extraction) operator so you can easily write
Poly obj; cin>>obj; cout<<obj;
Your will use the following input/output files to test your program.
Sample Input file Format
4 The number of polynomials used as inputs
3 1.00 0.00 1.00 1.00 1+x2+x3 First poly
4 -2.00 0.00 3.00 0.00 1.00 -2+3x2+x4 second
3 1.00 0.00 1.00 1.00 third
4 -2.00 0.00 3.00 0.00 1.00 fourth
In each line, the first number is the degree of that polynomial and the rest are the coefficients. The coefficients are in ascending power, following the format described in the “print()” function; For example, 4 -2.00 0.00 3.00 0.00 1.00 corresponds to (
-2+3x2+x4).