Lab 9: Polynomial Part 2 (100 pts) Due Tuesday, June 7 at 1:00pm on Catalyst and as a hard copy in class at 1:30pm Additional Polynomial Operations:
/**Public functions*/ Polynomial operator + (const Polynomial& p); Polynomial operator  (const Polynomial& p); //Multiplies the existing Polynomial by itself, returning a new Polynomial Polynomial distribute(double coefficient, int exponent); //Multiplies all of the terms of this Polynomial by the Term, //whose coefficient and exponent are given as parameters /**Private helper functions*/ Term addTerm(Term t1, Term t2); //A helper function for the + function and the  function //Adds two Terms together and returns the result as another Term Term multiplyTerm(Term t1, Term t2); //A helper function for the the square and distribute functions //Multiplies two terms together and returns the result as another Term Polynomial Operations: Add and Subtract
8.5x^{2} + 4.9x + 1.6 + 4.5x^{3} + 2.6x + 3.3
Polynomial Operations: Multiply and Square
(x + 1) (4x^{2} + 2x + 1) = 4x^{3} + 2x^{2} + x + 4x^{2 }+ 2x + 1 = 4x^{3} + 6x^{2} + 3x + 1
(4x^{2} + 2x + 1) * (4x^{2} + 2x + 1) = (4x^{2 }*^{ }4x^{2}) + (2x * 2x) + (1 * 1) + 2 * (4x^{2 }*^{ }2x) + 2 * (4x^{2 }*^{ }1) + 2* (2x * 1) = 16x^{4} + 16x^{3}+ 12x^{2} + 4x + 1
(3x^{5}) * (4x^{2} + 2x + 1) = 12x^{7} + 6x^{6} + 3x^{5} Sample Test File
/* * @author Jennifer Parrish #include <iostream> #include <iomanip> #include <fstream> #include "Polynomial.h" using namespace std; int main() { Polynomial poly; poly.insertTerm(4, 3.5); poly.insertTerm(3, 2.1); poly.insertTerm(2, 6.5); poly.insertTerm(1, 5.5); poly.insertTerm(0, 1); cout << "Printing P1. \nShould be 3.5x4 + 2.1x3 + 6.5x2 + 5.5x1 + 1x0: \n"; poly.print(); cout << endl << endl; Polynomial poly2; poly2.insertTerm(2, 3.3); poly2.insertTerm(1, 9.0); poly2.insertTerm(0,3.4); cout << "Printing P2. \nShould be 3.3x2 + 9.0x1 + 3.4x0\n"; poly2.print(); cout << endl << endl; Polynomial p_add = poly + poly2; cout << "Printing P3 = P1 + P2. \nShould be 3.5x4 + 2.1x3 + 9.8x2 + 14.5x1 + 4.4x0\n"; p_add.print(); cout << endl << endl; Polynomial p4; p4.insertTerm(5, 2.3); p4.insertTerm(4, 0); p4.insertTerm(3, 8.9); p4.insertTerm(2, 6.5); p4.insertTerm(1, 1.6); p4.insertTerm(0, 9.6); cout << "Printing P4. \nShould be 2.3x5 + 0.0x4 + 8.9x3 + 6.5x2 + 1.6x1 +9.6x0\n"; p4.print(); cout << endl << endl; Polynomial p5; p5.insertTerm(3, 3.1); p5.insertTerm(2, 3.1); p5.insertTerm(1, 3.1); p5.insertTerm(0, 3.1); cout << "Printing P5. \nShould be 3.1x3 + 3.1x2 + 3.1x1 + 3.1x0\n"; p5.print(); cout << endl << endl; Polynomial p6 = p4 + p5; cout << "Printing P6 = P4 + P5. \nShould be 2.3x5 + 0.0x4 + 12.0x3 + 9.6x2 + 4.7x1 + 12.7x0\n"; p6.print(); cout << endl << endl; Polynomial p7(p5); cout << "Printing copy of P5. \nShould be 3.1x3 + 3.1x2 + 3.1x1 + 3.1x0\n"; p7.print(); Polynomial p8 = p4  p5; cout << "Printing P8 = P4  P5. \nShould be 2.3x5 + 0.0x4 + 5.8x3 + 3.4x2 + 1.5x1 + 6.5x0\n"; p8.print(); Polynomial p9 = poly2.square(); cout << "Printing P9 = Square of P2. \nShould be 10.9x4 + 59.4x3 + 103.4x2 + 61.2x1 + 11.6x0\n"; p9.print(); Polynomial p10 = p5.distribute(4.2, 4); cout << "Printing P10 = P5 * 4.2x4." << endl; cout <<"Should be 13.0x7 + 13.0x6 + 13.0x5 + 13.0x4 + 0.0x3 + 0.0x2 + 0.0x1 +0.0x0\n"; p10.print(); cout << endl << endl; cout << "Evaluating p2 at 2.0. Should print 34.6: " << fixed << setprecision(1) << poly2.evaluate(2); } What To Submit:
How You Will Be Graded:
