A polynomial class c here is the header file Agencyhpp ifn
A polynomial class c++ here is the header file:
//
// Agency.hpp
#ifndef Agency_hpp
#define Agency_hpp
#include <stdio.h>
#include <iostream>
class Agency
{
public:
Agency();
Agency(int maxDegree, int* arrCoefficients);
Agency(const Agency& other);
~Agency();
int solve(int other);
Agency operator=(const Agency& poly);
bool operator==(const Agency& poly);
bool operator!=(const Agency& poly);
Agency operator+(const Agency& poly);
Agency operator-(const Agency& poly);
Agency operator*(const Agency& poly);
Agency operator*(int value);
//Friend Functions
friend std::ostream& operator<<(std::ostream& output, const Agency & poly);
friend std::istream& operator>>(std::istream& input, const Agency & poly);
//operator for freind functions << and >>
private:
int* coefficents;
int maxDegree;
bool isEqual(const Agency& poly);
Agency assign(const Agency& poly);
};
#endif /* Agency_hpp */
Description For this project you will create a polynomial class to represent polynomial expressions and write functions to operate on them. Some examples of polynomial expressions include (x4 2x 4), (4x 3 ,2 x), (x 5x 2), or (x 2) The class should contain the following private data members An integer array representing the coefficients of each term and the constant. An integer representing the maximum degree of the polynomial As an example: 4x x would be represented by an integer array with values 4-1 1 0 and an integer value of 3 representing the degree The following member function operators are required default constructor Initializes the degree to default size of 3 parameterized constructor Takes an integer representing the degree and an int* pointing to an array of coefficients and the constant Copy Constructor destructor solve Evaluates the polynomial at an integer (parameter) value and returns the result. As an example: x 2 when evaluated at 5 returns 27 operator Copies one polynomial to another operator JJ Returns true if two polynomials are equal operator 3: Returns true if two polynomials are not equal operator Multiplies together two polynomial expressions and returns a new polynomial of the product. This should work for polynomials of different sizes. As an example: (x4 2x 1) (x 3) returns (x3+5x2 7x 3) operator Takes an integer parameter scalar and returns a new scaled polynomial. As an example: (x3 2x2 3x 4) 5 returns (5x3 10x2 15x 20) operator Takes two polynomials and adds their coefficients and returns a new polynomial of the sum. As an example: (x2 3x 1) (2x 2) returns (x2 x 1)Solution
----------------------------------------------------------------------------------------------------------------------------------------------
another solution
Below is the the .h file we were provided with:
.cpp code-----------------------------------------
|   #include <iostream>  using namespace std;    class Polynomial  {  private:          int Nterms;          double* pCoeffs;// from lowest to highest order  public:          // functions          double evaluateAt(double x);          void print(void);        // constructor          Polynomial( double Coeffs[], int N_terms );// full construction from given array of coefficients          // destructor          ~Polynomial();// destructor VERY important this case      };    // full constructor. Must be passed an array of coeffs. and the array size.  Polynomial::Polynomial( double Coeffs[], int N_terms )  {          Nterms = N_terms;          pCoeffs = new double[ Nterms ];// allocate an array to hold the coefficient values          for(int i=0; i<Nterms; i++)                  pCoeffs[i] = Coeffs[i];// assign in straight order  }    // destructor - releases memory for the dynamically allocated coefficient array  Polynomial::~Polynomial()  {           if( pCoeffs )          {                  delete [] pCoeffs;                  pCoeffs = NULL;          }  }  // finds P(x)  double Polynomial::evaluateAt(double x)  {          double sum = 0.0;          double xPow = 1.0;          if( pCoeffs )                     for(int i=0; i<Nterms; i++)                  {                                                 sum += xPow*pCoeffs[i];// add up the terms                          xPow *= x;// build up the power of x from term to term                  }                   return sum;  }  // simple version produces crude output. Finetune to suit.  void Polynomial::print(void)  {          // 1st term          std::cout << pCoeffs[Nterms-1] << \"x^\" << Nterms-1;          // remaining terms          for(int i=Nterms-2; i>=0; i--)                                         std::cout << \" + \" << pCoeffs[i] << \"x^\" << i;                    return;  }    int main(void)// example use  {          // Pnum = 8*x^4 + 10*x^3 + x^2 + 29*x + 19                double Cnum[5] = { 19.0, 29.0, 1.0, 10.0, 8.0 };          Polynomial Pnum( Cnum, 5 );          cout << \"Pnum = \";          Pnum.print();          cout << \"\  Pnum(2.0) = \" << Pnum.evaluateAt(2.0) << endl;          return 0;  }   | 


