This is the driver program to test your Polynomial class. This file contains testing code to evaluate the correctness of
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
This is the driver program to test your Polynomial class. This file contains testing code to evaluate the correctness of
Polynomial) capacity = 10: terms = 0; turmArray = new Term capacity]: > main 1/ Copy constructor Polynomial const Polynomial source: // Destructor -Polynomial(); // Assignment operator Polynonial& operator - (const Polynomial source: // Sum of this and source polynomials Polynomial operator+(const Polynomial source); W/ Subtract of source polynomials from this Polynomial operator-(const Polynomial source); // Product of this and source polynomials Polynomial operator (const Polynomial& source) // Compute derivative of the current polynomial Polynomial Derivative(); 1/ Return true if left polynomial is identical to right polynomial bool operator (const Polynomialg source): 17 Evaluate polynomial this at x and return the result float Eval(float x): 1/ Create a new tern. If the term exists, overwrite its coefficient. void CreateTerm(const float coef, const int exp); W/ Print polynomial void Print) { if(terms w) std::cout << " << std::endl: else for(int ; icterms: 1.) { float c = termArray.coef; inte termArray.exp: ific > 86 i > e) std::cout << "+": > std::cout <<C; ifte > 0) std::cout<<"***<ce: 1 std::cout << std::endl; > int Capacity() const { return capacity: > int Terms) const { return ters:) Terns Get Termint x) const { return termrray);} private: Tern termArray: int capacity: I wax # of terms in this polynondal int terms: 1 current # of terms in this polynomial
include "polynomial.h" #include <iostream> int main() Polych Polynomial f. 9; f. CreateTern-4, 3); f.CreateTermt2.3, 2); f.CreateTerm{-3, 0); std::cout << ** = "; f.print(); g.CreateTerm[3, 4); 9. CreateTerm(-8, 0); g.CreateTerm(-4, 3); std::cout << " = "; g. Print(); g.CreateTerm(5.2); std::cout << "9 (creating a new tern) = 9. Print(); 1/ copy constructor test std::cout << "h created from f) = "; Polynomial h = f; h. Print(); 1/ assignment operator test std::cout << " (assigned from g) = "; h = 9: h. Print(); // Add test std::cout << " + 9 = "; hf + g; h. Print(); // Subtract test std::cout << "f-9 = "; hf - 9: h. Print(); // Equal test if(f = g) std::cout << "f and gare same" << std::endl; else std::cout << "f and g are different << std::endl; // Eval test std::cout << **(3.5) is "<f.Eval(3.5) << std::endl; 1/ Derivative test Polynomial i = f.Derivative(); std::cout << "Derivative of T="; 1. Print(); return 0;
Copy constructor Polynomial::Polynomial(const Polynomial source // TODO 3 1/ Destructor Polynomial::-Polynomial Poly.up // TODO > Polynoma Polynomial:: operator = (const Polynomials source // ToDo // Sum of this and source polynomials Polynomial Polynomial::operator +(const Polynomials source) Polynomial c: // ToDo return c: > Polynomial Polynomial:: operator - (const Polynomialg source) Polynomial c; // ToDo return c: Polynomial Polynomialstoperator - (const Polynomial source) { Polynomial c: // TODO return; > hool Polynomial :: operator (const Polynonial source) bool ret: // ToDo return ret: 3 float Polynomialsteval(float x) float ret = 0; // Tabo return Eet: 2 // Compute derivative of the current polynomial Polynomial Polynomial Derivative) Polynomis;
Polynomial Polynomial:: operator. (const Polynomialg source) Polynomial c; // ToDo return ci bool Polynomial::operator = (const Polynomialg source) bool ret; // ToDo return ret; } float Polynomial:: Eval(float x) { float ret = 8; // ToDo return ret; } 1/ Compute derivative of the current polynomial Polynomial Polynomial::Derivative() Polynomial c; // ToDo return ci 3 void Polynomial::Create Term(const float coef, const int exp) { // ToDo Poly opp