Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
9th Edition
ISBN: 9780134379319
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 16, Problem 2PC
Program Plan Intro

Arithmetic Exception

Program Plan:

  • Include the required header files.
  • Create SqrtException class for arithmetic exception.
  • Define the function mySqrt() that accepts the integer parameter.
    • Check whether the number is less than 0. If yes, throw arithmetic exception
    • Loop executes until the square of r is less than or equal to number.
      • Check whether square of r is equal to number. If yes,
        • Return r value.
    • There is no square root, then throw an arithmetic exception.
  • Define the “main()” function.
    • Read the inputs from the user.
    • In the Try block
      • Take square root of given number.
      • Display the square root of number.
    • In the Catch block,
      • Display the error message.

Blurred answer
Students have asked these similar questions
Python please: Write a square_root() function that takes a number and returns the square root. The square_root() function throws a ValueError object with the message "Exception: Negative input for square root entered." when the number is negative. Complete the main() program that reads a number from a user, calls the square_root() function, and outputs the returned value from the square_root() function. Use a try-except block to catch any ValueError object thrown by the square_root() function and output the exception message. If the user enters something other than an integer, the program throws a ValueError object with the message "invalid literal for int() with base 10: " and 'user_input'. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print('{:.2f}'.format(your_value)) Example: If the input is 100 the output is 10.00 Example: If the input is -55 the output is Exception: Negative input for square root entered. Example: If…
The problem comes from Introduction to C++ Programming and Data Structures, 4th Edition (HexFormatException)Implement the hex2Dec function in Programming Exercise 16.1 to throw a HexFormatException if the string is not a hex string .Define a custom exception class named HexFormatException. Write a test program that prompts the user to enter a hex number as a string and displays the number in decimal. If the function throws an exception, display "Not a hex number".
(Uncaught Exceptions) Write a program that illustrates that a function with its own tryblock does not have to catch every possible error generated within the try. Some exceptions can slipthrough to, and be handled in, outer scopes.

Chapter 16 Solutions

Starting Out With C++: Early Objects, Student Value Edition (9th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT