#include #include #include using namespace std; struct truncation { int dividend; int divisor; truncation(int initial_dividend, int initial_divisor) : dividend(initial_dividend), divisor(initial_divisor) {} }; class overflow {}; int main() { int status = EXIT_FAILURE; try { cout << "Please input the dividend and press RETURN: "; int dividend; //uninitialized variable cin >> dividend; cout << "Please input the divisor and press RETURN: "; int divisor; //uninitialized variable cin >> divisor; if (divisor == 0) { throw dividend; } if (dividend == INT_MIN && divisor == -1) { throw overflow(); } if (dividend % divisor != 0) { throw truncation(dividend, divisor); } cout << "The quotient is " << dividend / divisor << ".\n"; status = EXIT_SUCCESS; } catch (int i) { cerr << "Attempt to divide " << i << " by zero.\n"; } catch (const truncation& t) { cerr << "Truncation would result when dividing " << t.dividend << " by " << t.divisor << ".\n"; } catch (overflow) { cerr << "Integer overflow would result when dividing " << INT_MIN << " by -1.\n"; } catch (...) { cerr << "Caught unexpected exception.\n"; } return status; }