Versions Compared

Key

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

...

  1. Create a class called InvalidInputException that inherits from the std::exception class. This class will be used to handle invalid input errors.

  2. Add a constructor to the InvalidInputException 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 validateInput() that takes a double value as a parameter and checks if the input is within a specific range (e.g., between 1 and 100). The function should have the following signature:

    • void validateInput(double value)

  4. In the validateInput() function, check if the input value is within the specified range. If it's not, throw an instance of the InvalidInputException class with an appropriate error message.

  5. In the main() function, prompt the user for input values and demonstrate the usage of the validateInput() function. Take input values from the user and display whether the input is valid or not.

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

...