#include <iostream>
#include <cmath>
using namespace std;
class Polynomial {
private:
int degree;
int* coefficients;
public:
Polynomial(int deg, int* coeffs) : degree(deg), coefficients(coeffs) {}
~Polynomial() {
delete[] coefficients;
}
void printPolynomial() const {
for (int i = degree; i >= 0; i--) {
if (coefficients[i] != 0) {
if (i == degree)
cout << coefficients[i] << "x^" << i;
else {
cout << " ";
if (coefficients[i] > 0)
cout << "+";
cout << coefficients[i] << "x^" << i;
}
}
}
cout << endl;
}
};
int main() {
int degree = 4;
int* coeffs = new int[degree + 1];
coeffs[0] = 5;
coeffs[1] = 0;
coeffs[2] = 2;
coeffs[3] = -1;
coeffs[4] = 3;
Polynomial poly(degree, coeffs);
cout << "Polynomial: ";
poly.printPolynomial();
delete[] coeffs;
return 0;
}