# SI204 Polynomial Evaluation Problem

 ```#include using namespace std; int main() { // Read in x value // Read and evaluate polynomial // Write result return 0; } ``` ```#include using namespace std; int main() { // Read in x value /************************************/ /*** Read and evaluate polynomial ***/ /************************************/ while() { // Read next term c*x^n // Evaluate next term c*x^n // Update value of total } // Write result return 0; } ``` ```#include using namespace std; int main() { // Read in x value /************************************/ /*** Read and evaluate polynomial ***/ /************************************/ while() { // Read next term c*x^n /******************************/ /** Evaluate next term c*x^n **/ /******************************/ // - Compute x^n // - multiply by c // Add value of term to total } // Write result return 0; } ``` ```#include using namespace std; int main() { // Read in x value double x; cout << "Enter value for x: "; cin >> x; /************************************/ /*** Read and evaluate polynomial ***/ /************************************/ while() { // Read next term c*x^n /******************************/ /** Evaluate next term c*x^n **/ /******************************/ // - Compute x^n double xn = 1; for(int i = 0; i < n; i++) xn = xn*x; // - multiply by c double term = xn*c; /******************************/ /** Add value of term to total*/ /******************************/ if (op == '+') total = total + term; else total = total - term; } // Write result cout << "Result is " << total << endl; return 0; } ``` ```#include using namespace std; int main() { // Read in x value double x; cout << "Enter value for x: "; cin >> x; /************************************/ /*** Read and evaluate polynomial ***/ /************************************/ cout << "Enter polynomial to be evaluated " << "(e.g. 3.1*x^2 - 2.0*x^1 + 1.1*x^0 = )" << endl; while(op != '=') { /******************************/ /** Read next term c*x^n *****/ /******************************/ double c; int n; char t; cin >> c >> t >> t >> t >> n; /******************************/ /** Evaluate next term c*x^n **/ /******************************/ // - Compute x^n double xn = 1; for(int i = 0; i < n; i++) xn = xn*x; // - multiply by c double term = xn*c; /******************************/ /** Add value of term to total*/ /******************************/ if (op == '+') total = total + term; else total = total - term; } // Write result cout << "Result is " << total << endl; return 0; } ``` ```#include using namespace std; int main() { // Read in x value double x; cout << "Enter value for x: "; cin >> x; /************************************/ /*** Read and evaluate polynomial ***/ /************************************/ cout << "Enter polynomial to be evaluated " << "(e.g. 3.1*x^2 - 2.0*x^1 + 1.1*x^0 = )" << endl; // Initialization for loop char op; double total; op = '+'; total = 0; while(op != '=') { /******************************/ /** Read next term c*x^n *****/ /******************************/ double c; int n; char t; cin >> c >> t >> t >> t >> n; /******************************/ /** Evaluate next term c*x^n **/ /******************************/ // - Compute x^n double xn = 1; for(int i = 0; i < n; i++) xn = xn*x; // - multiply by c double term = xn*c; /******************************/ /** Add value of term to total*/ /******************************/ if (op == '+') total = total + term; else total = total - term; // Read next op cin >> op; } // Write result cout << "Result is " << total << endl; return 0; } ```

Christopher W Brown