#include #include "clist.h" #include "clistf.h" #include "poly.h" void main (void) { Poly equation[5]; // Array of equations Poly derivative[5]; // Array of derivatives Poly sum; // Sum of equations Poly dsum; // Derivative of sum double point[3]; // Three data points double slope; // Slope of tangent at point double value; // Value of sum equation int j, k; // Loop counters fstream fi; // Input stream fstream fo; // Output stream fi.open ("a:\\poly.dat", ios::in); if (fi.fail()) { cout << "Problem opening data file\n"; return; } fo.open ("a:\\poly.ans", ios::out); if (fo.fail()) { cout << "Problem opening result file\n"; return; } for (k = 0; k < 3; k++) fi >> point[k]; for (j = 0; j < 5; j++) { equation[j].Get(fi); // Read an equation derivative[j] = equation[j].Dx(); // Create the derivative sum = sum + equation[j]; // Add equation to sum fo << "\nFor "; equation[j].Put(fo); // Output equation for (k = 0; k < 3; k++) { // Evaluate at a point slope = derivative[j].Eval(point[k]); fo << "The slope at " << point[k] << " is " << slope << "\n"; } } fi.close(); dsum = sum.Dx(); // Take derivative of sum fo << "\nSum polynomial:\n"; sum.Put(fo); fo << "Derivative:\n"; dsum.Put(fo); fo << endl; for (k = 0; k < 3; k++) { value = sum.Eval(point[k]); // Compute value at point fo << "At " << point[k] << " the value is " // Compute slope << value << "; the slope is " << dsum.Eval(point[k]) << endl; } // The following statements should be uncommented if you do // the extra credit // fo << "The net area between " << point[0] << " and " << point[2]; // fo << " is " << sum.Integrate(point[0], point[2]) << endl; fo.close(); }