# include # include # include using namespace std; double f ( double x ); int main ( ) { bool foundn = false; bool foundp = false; bool foundz = false; double fx; double x; double xn; double xp; double xz; cout << "\n"; cout << "BRACKET:\n"; cout << " Enter a value X, to receive a function value F(X).\n"; cout << " Terminate with a CTRL-D or end-of-file.\n"; while ( true ) { cin >> x; if ( cin.eof ( ) ) { break; } fx = f ( x ); cout << " F(" << x << ") = " << fx << "\n"; if ( fx < 0.0 && !foundn ) { xn = x; foundn = true; } else if ( 0.0 < fx && !foundp ) { xp = x; foundp = true; } else if ( 0.0 == fx ) { xz = x; foundz = true; } } // // Search is over. // What did we find? // cout << "\n"; cout << " Bracket information:\n"; cout << "\n"; if ( foundn ) { cout << " F(" << xn << ") = " << f ( xn ) << "\n"; } if ( foundz ) { cout << " F(" << xz << ") = " << f ( xz ) << "\n"; } if ( foundn ) { cout << " F(" << xp << ") = " << f ( xp ) << "\n"; } return 0; } double f ( double x ) { double value; //value = cos ( x ) - x; value = pow ( x, 4 ) + 2 * pow ( x, 3 ) - 14 * pow ( x, 2 ) + 2 * x + 1; return value; }