hello, what i'm trying to do with this program is take something like 123456 and have it turn into this 1*x^2+3*x^4+5*x^6. i have code but i'm just lost in the whole idea of how to do it. so my code is probably completely wrong. if anyone knows how to do this or can help me fix my code (which i'm not sure is even close or not)
#include <iostream>
#include "math.h"
class term; //forward declaration
class poly{
public:
poly(){
int newTerm[];
termArray= newTerm[4];
capacity=4;
terms=0;
}
term *termArray;
int capacity;
int terms;
};
void poly::newTerm(const float theCoeff, const int theExp)
{
if(terms==capacity)
{
capacity *=2;
term *temp=new term[capacity];
copy(termArray, termArray +terms, temp);
delete []tempArray;
termArray=temp;
}
termArray [terms].coef=theCoeff;
termArray [terms++].exp=theExp;
}
class term {
friend class poly;
private:
float coef; //coefficient
int exp; //exponent
};
double poly::eval (double x){
double ans=0;
for (int i=0; i<terms; i++){
ans=ans+termArray[i].coeff*pow(x, termArray[i].exp);
return ans;
}
istream &operator >>(istream in, poly x);{
int a;
double b,c;
in>>a;
for <int i=0, i<a; i++)
{
in>>b>>c;
x.New Term (b,c);
}
return in;
}