Question
Write a function that accepts an integer parameter and returns its integer square root. The function should throw one of the following standard exceptions (or
Write a function that accepts an integer parameter and returns its integer square root. The function should throw one of the following standard exceptions (or 0) if one of the associated conditions are met with the related strings passed to the what() function:
throw domain_error: Error: Supplied integer is negative!
throw 0: Error: Supplied integer is zero!.
throw invalid_argument: Error: Supplied integer is not a perfect square!
Demonstrate the function with a suitable main function driver using user input and try/catch blocks, printing out any exception error strings (using the what() member function, or your own statement given 0). The main function exits with the corresponding return code or 0 if successful.
Main function return codes: 0:
It was passed a valid number. -1:
It is passed a negative integer. -2:
It is passed the integer 0. -3:
It is passed an integer that is not a perfect square.
NOTE: There are two types of 0s that you will be working with. 0, the exception, which will be thrown and caught meaning there was the error of a 0 being supplied by the user and sent to the function. And 0, the return type, which is the standard return code of the program terminating successfully. Please be aware of the two different meanings in the two different contexts. Being Computer Science students, you know that overloading happens all the time, and context is key. : )
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started