Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
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
Programming: C Language
Using C++
Write a void function GetYear that prompts for and inputs the year the operator was born (type int) from standard input. The function returns the user’s birth year through the parameter list (use pass by reference) unless the user enters an invalid year, in which case a BadYear exception is thrown. To test for a bad year, think about the range of acceptable years. It must be 4 digits (i.e. 1982) and it cannot be greater than the current year (the user obviously cannot be born in a calander year that has yet to happen!
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.
Chapter 16 Solutions
Problem Solving with C++ (10th 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
- Advantage of Finally in Exception Handlingjava Programarrow_forwardWrite a C++ program where one function throws an exception, and another function catches and handles itarrow_forwardLanguage: C++ Create a class called publication that stores the title (char array) and price (float) of a publication. From this class derive two classes: book, which adds a page count (int) and tape, which adds a playing time in minutes (float). Each of the three classes should have a getdata() function to get its data from the user using input from the keyboard and a putdata() function to display the data.Write a main function that creates an array of pointers to publication. In a loop, ask the user for data about a particular type of book or tape to hold data. Put the pointer to the object in the array. When the user has finished entering data for all the books and tapes, display the resulting data for all the books and tapes entered, using a for loop and a single statement such as: pubarr[j] -> putdata(); To display the data from each object in the array.arrow_forward
- Write a program in c++ opp The program must be included the following topics together In the same program with an explanation of each step.The topics are: VectorTemplate Exception Handling File StreamFriend function and Friend classarrow_forwardWrite a program using the C ++ OOP language, and the program should contain at least the following to four topics Inheritance Operator Overloading Vector Template Exception Handling File Stream Friend function and Friend class The following must be taken into account: 1- The arrangement 2-The idea of the program 3- The topics that have been chosen 4 - A simple explanation of the program's work 5- Writing comments explaining each step of the program 6- Show the implementation screenarrow_forwardUsing C++ Programming language: Assume you want a function which expects as parameters an array of doubles and the size of the array. Write the function header that accepts these parameters but is defined in such a way that the array cannot be modified in the function. You can use your own variable names for the parameters.arrow_forward
- You are assigned to develop a C++ Program using Classes, Functions, Arrays and Pointers that requires users to enter their own passwords. Your software requires that user’s passwords meet the following criteria: The password should be at least sixteen (16) characters long. The password should contain at least: one uppercase letter one lowercase letter one digit one special character (no spaces) Write a program that asks for a password and then verifies that it meets the stated criteria. If it doesn’t, the program should display a message telling the user why. Whenever possible, use pointers. Manually destroy any memory used when finished using it.arrow_forwardin c++ Write a function named createTwoNames that will do the following: - Read in a word and its definition - Create the Word object for that word and definition - Read in an item’s name and its price - Create the Item object for that item - It will return an array of two pointers pointing to these newly created Word and Item objects. It will use try-catch statement to handle the exception. If the user enters an empty or all-blank word or definition or item’s name, it will not create the object(s) and return null for that object only. In another words, it may create 0, 1 or 2 objects. Whenever the error occurs, it must print out the correct error reason: empty or blank (but not both). Note that this function can and will use cin and cout to read in values from the user.arrow_forwardDesign a Customized Exception Java program * Consider a case and write a short description about your case. *Draw a flowchart of your designarrow_forward
- PROGRAMMING LANGUAGE: C++ You need to store hiring date and date of birth for teachers, and for students store their admission date and date of birth. You need to create a Date class for this purpose. Create objects of Date class in Teacher and Student class to store respective dates. You need to write print function in Teacher and Student classes as well to print all information of Teachers and Students. You need to perform composition to implement this task. Create objects of Teacher and Student classes in main function and call print function for both objects. Print Date class here. Print updated Teacher class here. Print updated Student class here. Print main function here. Print Outputshere.arrow_forwardA destructor function is called automatically when the object goes out of scope: I. the function ends II. the program ends III. a block containing local variables endsarrow_forwardC++ code please (5) Implement the FindText() function, which has two strings as parameters. The first parameter is the text to be found in the user provided sample text, and the second parameter is the user provided sample text. The function returns the number of instances a word or phrase is found in the string. In the PrintMenu() function, prompt the user for a word or phrase to be found and then call FindText() in the PrintMenu() function. Before the prompt, call cin.ignore() to allow the user to input a new string.Ex: Enter a word or phrase to be found: more "more" instances: 5arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
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 PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
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
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage