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;
        }

Regrettably, no need to criticize or edit this code. Yes, it's completely (syntactically and semantically) wrong. It seems the only medicine is to rewrite it from the scratch.

Better try to define correct (and useful) class Poly specifications. For example, either the next two strings (or numbers? ) define the same polynom: "1111" and "21" or the 1st one is wrong? What do you want to do with this class objects except initialize them (incorrectly) from input streams? Now the class looks like a classic black hole. Do you want to evaluate this polynom of x and what's the type of the polynom value (int, double or what else)?..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.