Starting Out with C++: Early Objects (9th Edition)
Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
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
use C++ programing language  Write a program that prompts the user to enter a person's date of birth in numeric form such as 8-27-1980. The program then outputs the date of birth in the form: August 27, 1980. Your program must contain at least two exception classes: invalidDay and invalidMonth. If the user enters an invalid value for day, then the program should throw and catch an invalidDay object. Similar conventions for the invalid values of month and year. (Note that your program must handle a leap year.)
def test_func(a,b,c): return (a+b)/c This function is normally designed to be used with three numbers: a, b, and c. However, a careless coder may call this function with an ill combination of arguments to cause certain exceptions. Specifically, if any of a, b or c is not a valid number, then this code will produce a TypeError; and if a and b are valid numbers, and c is 0, then the code will produce a ZeroDivisionError. Your job is to enhance this function by adding proper try...except... blocks, surrounding and capturing the exceptions. When a TypeError occurs, instead of crashing, your code must print on the screen: "Code produced TypeError". And, when a ZeroDivisionError occurs, instead of crashing, your code must print on the screen: "Code produced ZeroDivisionError". In both cases, your function will not crash, will not throw an exception, and silently return None.
Subject: Object Oriented PrgrammingLanguage: Java ProgramTopic: Exception (SEE ATTACHED PHOTO FOR THE PROBLEM)

Chapter 16 Solutions

Starting Out with C++: Early Objects (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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning