Problem Solving with C++ plus MyProgrammingLab with Pearson eText-- Access Card Package (9th Edition)
9th Edition
ISBN: 9780133862218
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 16, Problem 6PP
Program Plan Intro
- Include required library files.
- Define a “throwExcepAt()” function to throw exception at user input level.
- Check “currLevel” is not equal to “excepLevel” using “if” statement.
- The condition is true, print calling depth.
- Call “throwExcepAt()” function to calling depth recursively.
- Define a “main()” function.
- Declare and initialize an integer variable.
- Get the input from user to throw exception.
- Assign the input to the variable.
- “try” block to call “thrwoExcepAt()” function with two arguments
- “catch” block to print the exception thrown message.
- Check “currLevel” is not equal to “excepLevel” using “if” statement.
- The condition is true, print calling depth.
- Call “throwExcepAt()” function to calling depth recursively.
- Declare and initialize an integer variable.
- Get the input from user to throw exception.
- Assign the input to the variable.
- “try” block to call “thrwoExcepAt()” function with two arguments
- “catch” block to print the exception thrown message.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Design two functions with an exception-specification lists as follows: a. A function which can throwonly an integer exception b. A function which can throwonly a string exception
Take a look at the following hypothetical scenario: A function can throw an exception. What are the three possible functions of the function?
Write a programmer defined function to find the perimeter of circle. Add a decorator function to validate the input radius to check less than or equal to zero. If the radius is less than or equal to zero, raise an exception.
Chapter 16 Solutions
Problem Solving with C++ plus MyProgrammingLab with Pearson eText-- Access Card Package (9th Edition)
Ch. 16.1 - Prob. 1STECh. 16.1 - What would be the output produced by the code in...Ch. 16.1 - Prob. 3STECh. 16.1 - What happens when a throw statement is executed?...Ch. 16.1 - In the code given in Self-Test Exercise 1, what is...Ch. 16.1 - Prob. 6STECh. 16.1 - Prob. 7STECh. 16.1 - What is the output produced by the following...Ch. 16.1 - What is the output produced by the program in...Ch. 16.2 - Prob. 10STE
Knowledge Booster
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
- Write a PYTHON code with at least 2 functions (one should call the other). The function which is called by the first function should also be able to be called directly. Execute these functions with various parameters such that you can demonstrate the following: Each function should have some debug code so you can trace calls to the functions and activity within the functions. Each should handle at least 2 types of exceptions (both shouldn't handle the same exceptions). The function called by the first one should, at some point, generate a division by zero error, but should NOT handle this error. The function that calls the division by zero function should handle a division by zero error. Catch one error and raise a different one. Have some finally code (perhaps with some debugging output) Demonstrate & explain: call the division by zero function both from your main program and from the other function. show that the exception isn't handled by the function itself but by the other…arrow_forward2. Create a program of your own choice and show a. The use of try-catch-finally block for exception handling. b. The use of throw keyword for exception handling. c. The use of throws keyword for exception handling.arrow_forwardThis lab will exercise your understanding of some of the concepts covered in Chapter 14: exception handling 1. Create a program that uses EXCEPTION HANDLING to deal with an invalid input entry by a user. a. Write a program that prompts a user to enter a length in feet and inches. The length valuesmust be positive integers. b. Calculate and output the equivalent measurement in centimeters1. inch = 2.54 centimeters c. Write the code to handle the following exceptions: If the user enters a negative number, throw and catch an error that gives the user the appropriate message and request a valid number. Do this until the user enters a valid number If the user enters a character, throw and catch an error that indicates the input stream is invalid. Write code that resets the input stream and request a valid number. Do this until the user enters a valid number d. Output the feet-inch input values to centimeter conversion value The program may be named any name of our choice, must have a .cpp…arrow_forward
- in c++ Write a function named createOneStudent that will read in from the user the student info: id, name and gpa. It will use try-catch to handle the exception if the user provides a negative id or gpa that is out of bound (< 0.0 or > 4.0) by asking the user to re-enter them. It must provide the correct reason for the error and the actual error value. Then it will allow the user to try up to 3 times. This function will return the pointer of a newly created Student object or nullptr if the info is still incorrect. Note that this function can and will use cin and cout to read in values from the user. Here is an example of a run up to 3 times: Enter ID: -1 Enter GPA: 4.0 Enter name: John Smith Exception: negative id: -1 Enter ID: 1234 Enter GPA: 5.0 Enter name: John Smith Exception: out of bound gpa: 5.00 Enter ID: 1234 Enter GPA: 4.0 Enter name: John Smith ID(1234) NAME(John Smith) GPA(4.00) Here is an example of a run of 3 times and still not able to create it: Enter ID: 1234…arrow_forwardSuppose you are writing a C++ function that has three alternativeapproaches for accomplishing its requirements. Write a skeletal versionof this function so that if the first alternative raises any exception, thesecond is tried, and if the second alternative raises any exception, thethird is executed. Write the code as if the three methods were proceduresnamed alt1, alt2, and alt3.arrow_forwardc++ Create a program that takes the square root of a number using the concepts of exception handling. In the implementation of main, you will call the function Sqrt and pass as argument an integer value (positive or negative). If all goes well, main will display the square root of the value provided. The function Sqrt will throw the integer value -9999 as error if the value provided by main is negative. If it is not negative, then it will take the square root of the value using the function Sqrt from the cmath library (Note: You're making your own Sqrt function and using the cmath's function Sqrt inside Sqrt). main should appropriately handle ANY exception thrown by Sqrt.arrow_forward
- Write a program that reads integers user_num and div_num as input, and output the quotient (user_num divided by div_num). Use a try block to perform all the statements. Use an except block to catch any ZeroDivisionError as a variable and output "Zero Division Exception: " followed by the exception message from the variable. Use another except block to catch any ValueError caused by invalid input as a variable and output "Input Exception: " followed by the exception message from the variable. Note: ZeroDivisionError is raised when a division by zero happens. ValueError is raised when a user enters a value of different data type than what is defined in the program. Do not include code to raise any exception in the program. (in Python)arrow_forwardWrite a program that reads integers user_num and div_num as input, and output the quotient (user_num divided by div_num). Use a try block to perform all the statements. Use an except block to catch any ZeroDivisionError as a variable and output "Zero Division Exception: " followed by the exception message from the variable. Use another except block to catch any ValueError caused by invalid input as a variable and output "Input Exception: " followed by the exception message from the variable. Note: ZeroDivisionError is raised when a division by zero happens. ValueError is raised when a user enters a value of different data type than what is defined in the program. Do not include code to raise any exception in the program. Ex: If the input of the program is: 15 3 the output of the program is: 5 Ex: If the input of the program is: 10 0 the output of the program is: Zero Division Exception: integer division or modulo by zero Ex: If the input of the program is: 15.5 5 the output of…arrow_forwardUse Standard Exceptions to write a program with a function called safe_divide that takes two double arguments and returns a double corresponding to the result of dividing the first argument by the second argument. Before performing the division, the function should check to determine if division by zero would occur. If division by zero would occur, instead of performing the division, the function should throw an exception of type std::invalid_argument. pls help answer this code in c++arrow_forward
- Consider the following fictitious scenario: A function throws an exception. What are the three possible functions of the function?.arrow_forwardConsider this hypothetical: Functions may throw exceptions. Which three functions does it have?arrow_forwardWrite a program that throw s an exception from a deeply nested function and still has the catch handler following the try block enclosing the initial call in main catch the exception.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT