Answer the question
In order to leave comments, you need to log in
Implementing "polynomial" class with dynamic array?
The coefficients are not written to the array k, and this is the problem. (Parallel question - since I messed up - is it possible at all? That is, right?)
class polynom {
int polynomsize;
float *k;
//float k[100];
public:
// Конструктор с параметрами, инициализирующий степень полинома и выделяющий память под массив.
polynom(int S,float K[]) {
polynomsize = S;
float *k = new float[polynomsize];
for(int i=0; i<polynomsize; ++i)
k[i]=K[i];
}
string get() {
string s="[Poly] ";
for (int i=0; i<polynomsize; i++) {
if (k[i]!=0)
if ((polynomsize-i-1)!=0)
s+=to_string(k[i])+"x^"+to_string(polynomsize-i-1)+" + ";
else s+=to_string(k[i]);
}
return s;
}
void div(float n) {
for (int i=0; i<polynomsize; i++) {
k[i]=k[i]/n;
}
}
~ polynom(){
delete[] k;
cout << "destructor worked";
};
};
Answer the question
In order to leave comments, you need to log in
float *k = new float[polynomsize];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question