Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Create a class called DivideByZeroException that inherits from the std::exception class. This class will be used to handle divide-by-zero errors.

  2. Add a constructor to the DivideByZeroException class that takes a const char* message as a parameter and passes it to the base std::exception class constructor.

  3. Create a function called safeDivision() that takes two double values as parameters (numerator and denominator) and returns the result of their division as a double. The function should have the following signature:

    • double safeDivision(double numerator, double denominator)

  4. In the safeDivision() function, check if the denominator is zero. If it is, throw an instance of the DivideByZeroException class with an appropriate error message. If it's not, return the division result.

  5. In the main() function, demonstrate the usage of the safeDivision() function with various input values. Take the input values from the user and display the results.

  6. Use a try-catch block in the main() function to catch any DivideByZeroException exceptions thrown by the safeDivision() function. If an exception is caught, display the error message from the exception.

...