#include #include #include #include "Polynomial.h" using namespace std; int main( int argc, char* argv[] ) { if ( argc != 2 ) { cerr << "Usage: " << argv[0] << " output.txt\n"; return 0; } ofstream out_str( argv[1] ); if ( !out_str ) { cerr << "Failed to open " << argv[1] << '\n'; return 0; } Polynomial f; double x = 2.5; double r = f( x ); out_str << "1: f(" << x << ") = " << r << '\n'; f.add_term( 4, 0 ); f.add_term( 5, 3 ); f.add_term( 2, 0 ); f.add_term( -1, 1 ); f.add_term( -1, 5 ); out_str << "2: After 5 add_term calls: f(x) = " << f; vector coefficients, exponents; coefficients.push_back( 1 ); coefficients.push_back( -1 ); exponents.push_back( 2 ); exponents.push_back( 0 ); exponents.push_back( 10 ); // will be ignored Polynomial f1( coefficients, exponents ); out_str << "3: f1(x) = " << f1; coefficients[1] = 1; Polynomial f2( coefficients, exponents ); out_str << "4: f2(x) = " << f2; Polynomial f3 = f1+f2; out_str << "5: f1+f2 = " << f3; Polynomial f4 = f1-f2; out_str << "6: f1-f2 = " << f4; Polynomial f5 = f1*f2; out_str << "7: f1*f2 = " << f5; f1.add_term( 3, 4 ); f1.add_term( 2, 5 ); f1.add_term( -8, 7 ); out_str << "8: f1(x) = " << f1; out_str << "9: f1(2.0) = " << f1(2.0) << endl; f2.add_term( -3, 4 ); f2.add_term( 2, 5 ); f2.add_term( 1, 6 ); f2.add_term( 3, 8 ); out_str << "10: f2(x) = " << f2; f3 = f1+f2; out_str << "11: f1+f2 = " << f3; f4 = f1-f2; out_str << "12: f1-f2 = " << f4; f5 = f1*f2; out_str << "13: f1*f2 = " << f5; return 0; }