Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions