Question: Correct the errors in the following program: // Debugging: debugging.cpp #include #include using namespace std; // class InvalidInputTypeException definition class InvalidInputTypeException { public: // constructor

Correct the errors in the following program:

// Debugging: debugging.cpp #include #include using namespace std; // class InvalidInputTypeException definition class InvalidInputTypeException { public: // constructor InvalidInputTypeException() : message( "entered input of the wrong data type" ) { empty } // end class InvalidInputTypeException // function what definition const char *what() const { return message.c_str(); } // end function what private: string message; }; // end class InvalidInputTypeException // class OutOfRangeException definition class OutOfRangeException { public: // constructor exception OutOfRangeException() : message( "entered a number not in the valid range" ) { // empty } // end class OutOfRangeException constructor // function what definition const char *what() const { return message.c_str(); } // end function what private: string message; }; // end class OutOfRangeException // function inputNumber definition int inputNumber() { int number; cout << "Enter an integer from 1 to 100 (-1 to end): "; cin >> number; if ( cin.fail() == 1 ) throw( InvalidInputTypeException ); if ( number > 100 || number < 1 ) throw exception( OutOfRangeException() ); if ( num == -1 ) throw; return number; } // end function inputNumber int main() { int num1 = 0; int num2 = 0; double result; // only way to exit this loop is an exception while ( true ) { number1 = inputNumber(); number2 = inputNumber(); try { result = static_cast< double >( number1 ) / number2; cout << number1 << " / " << number2 << " = " << result << endl << endl; } // end try catch ( ... ) { cout << "An unknown exception has occurred, " << "exiting the program " << e.what() << endl; exit( 0 ); }; // end catch catch ( InvalidInputTypeException &e ) { cout << "Exception occurred: " << e.what() << ' '; cin.clear(); cin.ignore(); } // end catch catch ( OutOfRangeException &&e ) cout << "Exception occurred: " << e.what() << ' '; } // end while } // end main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!