// 22.5HV2 Software Engineering II // Unit 1 Exercise 3 #include #include float poly(float, float, float, float=0, float=0, float=0, float=0); void main() { int i, order; float x, coeff[6]; cout << "Enter order of polynomial (1-5) : "; cin >> order; for (i=0;i<=order;i++) { cout << "Enter coefficient for power " << i << " : "; cin >> coeff[i]; } cout << endl << "Enter value of x: "; cin >> x; cout << endl << "The value of the polynomial is "; cout << setprecision(3); switch (order) { case 1: cout << poly(x,coeff[0],coeff[1]); break; case 2: cout << cout << poly(x,coeff[0],coeff[1],coeff[2]); break; case 3: cout << poly(x,coeff[0],coeff[1],coeff[2],coeff[3]); break; case 4: cout << poly(x,coeff[0],coeff[1],coeff[2],coeff[3],coeff[4]); break; case 5: cout << poly(x,coeff[0],coeff[1],coeff[2],coeff[3],coeff[4],coeff[5]); break; } cout << endl; } float poly(float x, float a, float b, float c=0, float d=0, float e=0, float f=0) { return a + b*x + c*x*x + d*x*x*x + e*x*x*x*x + f*x*x*x*x*x; }