C++ How to Program (10th Edition)
C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 17, Problem 17.28E
Program Plan Intro

Program Plan:

  • Include header file.
  • Declare and define class DivideByZeroException by inheriting runtime_error class.
  • Declare and define a class "test"
    • Declare two private data members: x and y.
    • Make constructor accepting two integer values.
    • Check if second value is zero, and throw exception whose handler will be found main() function, else put values in x and y.
    • Make function "divide()", which will display result of dividing "x/y".
    • End class "test".
  • Start the main() function.
    • In the try block, accept two integers, and create object "t" of class "test", which will call the constructor using two integers entered.
    • If second value entered is zero, catch will handle the exception thrown from the constructor, and display the message.
    • Return and exit.

Blurred answer
Students have asked these similar questions
(Creating Custom Exception Class) Write a Password class that stores a password string. Passwords must contain at least seven alpha-numeric characters, with at least one letter and one digit. Also write an InvalidPasswordException class that extends Exception. The  Password constructor should throw an InvalidPasswordException, which should report an appropriate message based on a given string (e.g. if the string contains no digits, the exception should report this fact).  Write a GUI program to prompt the user to enter a password and report an InvalidPasswordException if an invalid password is entered. Please teach and help me how to deisgn the program based on the two files given .Some sample screenshots are shown below: InvalidPasswordException.java public class InvalidPasswordException extends Exception{    public InvalidPasswordException (String errMsg){        super(errMsg);    }    }   Password.java public class Password  {private String passwordstr;       public…
Checked exceptions in Java are those exceptions that are checked at compile time and must be either caught or declared in the method's throws clause. (True/False)
(Throwing Exceptions from a catch) Suppose a program throws an exception and the appropriate exception handler begins executing. Now suppose that the exception handler itself throwsthe same exception. Does this create infinite recursion? Write a program to check your observation.
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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning