Details of this Paper

C++ arithmetic Program

Description

solution


Question

Write a function that accepts an integer parameter and returns its integer square root. The function should throw an exception if it is passed an integer that is not a perfect square. Demonstrate the function with a suitable driver program;NOTE: Add the following condition to the program: Whenver the user enters non-integer data, throw an exception telling the person what is wrong.;Here are some hints that may help with problem 2 - Arithmetic Exceptions.;First of all, I've added a program in your Content area: dataType. I recommend that you take a look at it. It is a little sample program that checks to make sure the user entered integer data. Your program is to throw an exception if character data is entered (NOTE: I added this restriction in the dropbox area with the instructions.) That is in addition to the exception that the book asked you to throw.;Now the other part of the problem is how to tell when you have a perfect square. Here are a couple of approaches;1.) You could use the sqrt function (needs to include the cmath header) and check to see if the result is an integer.;or;2.) You could create a loop starting at 1 and squaring each integer until you match the integer entered by the user (means perfect square) or until the square is larger than the number entered (means not a perfect square)

 

Paper#64001 | Written in 18-Jul-2015

Price : $37
SiteLock