Notes for assignment #3

const maxorder = 100;

class polynomial

{

int order;

double a[maxorder+1];

public:

void read();

void write();

double eval_straight(double x);

double eval_horner(double x);

};

void polynomial::read()

{ // make it more interactive

cin >> order;

for(int j = order; j >= 0; j--)

cin >> a[j];

}

double polynomial::eval_straight(double x)

{

double sum = 0;

for(int j = order; j >= 0; j--)

sum += a[j]*power(x,j);

}

void main()

{

polynomial p;

p.read();

cin << x; // make it interactive

cout << "Results of polynomial: ";

p.write();

cout << p.eval_straight(x); // make it more beautiful

cout << p.eval_horner(x);

}