C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 17, Problem 17.31E
Program Plan Intro
- Including header file.
- Declare and define four functions as follows
- func4() -throws exception
- func3() - call func4()
- func2() - call func3()
- func1() - call func2()
- Start main() function
- Call func1() inside try catch block
- Return and exit.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Python Code:
Write a function that takes a single number as an argument:
1) This function should then check whether a number is an even number (2,4,6,8) and raise an exception if otherwise
2) Call this function with an uneven number first without catching the exception and then with catching the exception and printing a warning to the user afterwards
Bonus: Do the same as the above but instead implement your solution for prime numbers and call the function with a non-prime number
How do you raise an exception in a function?
[Access Control Policy]: A computer system usually implements the exception
handling mechanism. Like the interrupt handling mechanism, the original program
flow will be stopped until the exception is handled. For example, when a program is
calculating c=a/b, and for some reason b was set to 0, the program will encounter
the "Division by Zero" exception. The control will be given to the exception handler,
and the recovery action could be "report only", "return to the next instruction",
"purge the program", etc., based on the severity of the problem. From the abov
information, we can conclude:
A computer system can integrate both Discretionary Access Control (DAC) and Mandatory
Access Control (MAC) security policies
An administrator can inhibit the exception handling
The exception handling mechanism is like the Mandatory Access Control security policy, no
matter which user caused the exception (even the administrator), the program should be
stopped, and the control should be given to the…
Chapter 17 Solutions
C++ How to Program (10th Edition)
Ch. 17 - (Exceptional Conditions) List various exceptional...Ch. 17 - (Catch Parameter) Under what circumstances would...Ch. 17 - (throw Statement) A program contains the statement...Ch. 17 - (Exception Handling vs. Other Schemes) Compare and...Ch. 17 - Prob. 17.19ECh. 17 - Prob. 17.20ECh. 17 - Prob. 17.21ECh. 17 - (Catching Derived-Class Exceptions) Use...Ch. 17 - (Throwing the Result of a Conditional Expression)...Ch. 17 - Prob. 17.24E
Knowledge Booster
Similar questions
- (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.arrow_forwardWhat is the purpose of exception specifications? How do you declare a throw list? Can you declare multiple exceptions in a function declaration?arrow_forwardCan this be done in C++. I need some code to compare too.arrow_forward
- Please answer all the questions, thank you!arrow_forward(True/False): In protected mode, each procedure call uses a minimum of 4 bytes of stackspace.arrow_forwardComputer Science Help please! I need my code to use an exception handling method to check if the user entered a correct word. Here is the logic: When given two words, the child may claim that transformation of the first word into the second is possible. In this case, the program asks the child to demonstrate the correctness of the answer by typing a sequence of words starting with the first and ending with the second. Such a sequence is an acceptable proof sequence if each word is obtained from its predecessor by swapping a single pair of adjacent letters. For example, the sequence tops, tosp, tsop, stop, sotp, sopt, spot proves that the word tops can be transformed into spot. If the proof sequence is accepted, the child earns a point and play proceeds to the next round with a fresh pair of words. A proof sequence is rejected if a word cannot be obtained from its predecessor by swapping an adjacent pair of letters, or if the first word in the sequence is not the first word of the pair…arrow_forward
- Consider the following scenario: a function throws an exception. What are the three things that the function is capable of performing?arrow_forward(Replace strings) Write the following function that replaces the occurrence of a substring old_substring with a new substring new_substring in the string s. The function returns true if string s is changed, and otherwise, it returns false. bool replace_strings (string& s, const string& old_string, const string& new_string) Write a test program that prompts the user to enter three strings, i.e., s, old string, and new_string, and display the replaced string.arrow_forward(Intro to Java) Tracking Customers This program will read in a series of names, along with an associated gender, from an input file of unknown length. The program uses a while loop to read in each name from the file by using the hasNextLine() method from the Scanner class. Please use a while loop for practice, although you could also write this assignment using a for loop to read from the file. As you read in each name, you will store it in an array, along with a title (Mr. or Ms. or Mx.) dependent on the stated gender. The first line of each file will contain the number of names contained in the file (hint: this is the same structure as the input file in your assignment 18.2). Additionally, this program should have two methods, as follows: The first method: The method is named extractInitial It takes a String parameter It extracts the first letter (initial) from the String parameter It returns a char for the initial. Note: You must write a complete Javadoc for this method to…arrow_forward
- b) Rewrite the code in Figure 2 to include exception handlers to catch arithmetic exception and number format exception which is a simple calculator that can automatically add, multiply, subtract and divide two numbers that have been inputted by users. The arithmetic exception will be displayed with exception message. The number format exception will give error messages for both num1 and num2 if string inputs are not parsed as integer. private String evaluate() { int num1 Integer.parseInt(numStr1); Integer.parseInt(numStr2); int num2 int result = 0; switch (op) { case '+': result = num1 + num2; break; case '-': result = num1 - num2; break; case result = num1 * num2; break; case '/' : result = num1 / num2; } return String.valueOf(result); } }arrow_forward(In java) Lab6C: Cha-Ching For this lab, use a do-while loop.A sentinel loop is a loop (a special while loop or a do-while loop) that continues to process data until itreaches a specific value(s) that signals that it should stop looping; this special value(s) is usuallyindicated as the condition of the while or do-while loop. A good example of a sentinel loop is the whileloop that you had to write to verify user input in Lab6B, the special values were anything in the range of1 to 1000. Another very common application for this is allowing a user to rerun a program.Please write a very simple program that mimics a bank account. The program should start the user outwith $1000. The program should print out a welcome menu once with the options present for the user.The program should allow the user to make a deposit, withdrawal, and see their current balance.Every time the user deposits or withdraws, the program should show the user their new balance; itshould also ask the user if they want…arrow_forwardplease fix the issue hihlighted in yellow and please check my code. In python language: 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 and output an exception message. Use another except block to catch any ValueError caused by invalid input and output an exception message. Note: ZeroDivisionError is thrown when a division by zero happens. ValueError is thrown when a user enters a value of different data type than what is defined in the program. Do not include code to throw 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 the program is: Input Exception: invalid literal for…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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 LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT