Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

17. Understand the challenges of multilingualism.

Answered: 1 week ago

Question

1. Select the job or jobs to be analyzed.

Answered: 1 week ago