use clion if applicabale, if not any program is ok The goal of this assignment i
ID: 3848519 • Letter: U
Question
use clion if applicabale, if not any program is ok
The goal of this assignment is to reinforce the dynamic classes in C++. Specifically, the assignment is to re-implement only using a dynamic array to store the coefficients. This class needs to have a destructor, copy constructor, and an overloaded assignment operator. An object of this polynomial class will only store the necessary coefficients (if the polynomial has degree n, then only n + 1 coefficients will be stored. You should start by modifying the header file from assignment 3.You need to supply a test program.Explanation / Answer
Program:
#ifndef POLY_H
#define POLY_H
#include <iostream> // Provides ostream
namespace colorado_edu
{
class polynomial
{
public:
static const unsigned int MAXIMUM_DEGREE = 29;
double* pCoeffs; //Dynamic Array
polynomial(double c = 0.0, unsigned int exponent = 0);
void add_to_coef(double amount, unsigned int exponent);
void assign_coef(double coefficient, unsigned int exponent);
void clear( );
polynomial antiderivative( ) const;
double coefficient(unsigned int exponent) const;
double definite_integral(double x0, double x1) const;
unsigned int degree( ) const { return current_degree; }
polynomial derivative( ) const;
double eval(double x) const;
bool is_zero( ) const;
unsigned int next_term(unsigned int e) const;
double numeric_definite_integral(double x0, double x1, unsigned int n);
unsigned int previous_term(unsigned int e) const;
double operator( ) (double x) const { return eval(x); }
~polynomial()
{
if( pCoeffs )
{
delete [] pCoeffs;
pCoeffs = NULL;
}
}
private:
double coef[MAXIMUM_DEGREE];
unsigned int current_degree;
};
polynomial operator +(const polynomial& p1, const polynomial& p2);
polynomial operator -(const polynomial& p1, const polynomial& p2);
polynomial operator *(const polynomial& p1, const polynomial& p2);
std::ostream& operator << (std::ostream& out, const polynomial& p);
void make_gif(
const polynomial& p,
const char filename[ ],
double low_x,
double high_x,
double low_y,
double high_y
);
}
#endif
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.