Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am writing a c++ program and I need help with implementor the template class a

ID: 3808487 • Letter: I

Question

I am writing a c++ program and I need help with implementor the template class and main. I set up the header file. Please help me with it. I am asking same question around 5 times.The item is the template class.

like template<class T>

//header file

#ifndef POLYNOMIAL_H

#define POLYNOMIAL_H
#include

namespace torunian_14
{
   template
   class Polynomial
   {
   private:
       Item* data = new Item[4]; //stores the coefficients
       int arraySize; //stores the current size of the array
       int polyDegree; // stores the current degree of the polynomial

   public:
       Polynomial();
       Polynomial(Item a0);
       Polynomial(const Polynomial& source);
       ~Polynomial();

       void addToCoef(Item amount, unsigned int k);
       void assignCoef(Item newCoefficient, unsinged int k);
       void clear();
       void reserve(size_t number);

       Item coefficient(unsigned int k) const;
       unsigned int degree() const;
       unsigned int nextTerm(unsigned int k) const;

       Item eval(Item x) const;
       Item operator ()(Item x) const;

       //addition, subtraction, and multiplication operators would all be good
       void operator +=(const Polynomial& addend);
       void operator -=(const Polynomial& subend);
       void operator *=(const Polynomial& multiple);

       Polynomial& operator =(const Polynomial& source);
       Polynomial& operator =(Item a0);
   };

  
}
#include "6_6_PolynomialTemplate.template"   //include implementation
#endif

Explanation / Answer

The common procedure in C++ is to put the class definition in a C++ header file and the implementation in a C++ source file.Then the source file is made part of the project ,meaning it is compiled separately but when we implement this procedure for template classes Some compilation and linking problems will arise.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote