STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 16, Problem 2RQE
Program Description Answer
The “try” block contains a block of statements which may cause an exception to be thrown.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
DIRECTION: Using Java as program language Create a simple program for a quiz bee with a class named QuizBee. The program shall:o Contain an array of 15 multiple choice questions with three (3) choiceseach and;o Require the user to choose among A, B or C.o Note: Cases are ignored. Lowercase letters are acceptable (a,b, or c) Create a try-catch structure to handle three (3) exceptions. These are when theuser inputs the following:o An invalid letter (not A, B or C)o A number or any special character.o Blank (no answer). Prompt the user to answer again if any of the three (3) exceptions is thrown. Display the score, number of incorrect answers and corrects answers.
C++
Each Fraction contains a numerator, denominator, a whole number portion, and has access to several functions you have developed, including overloaded operators. Complete these tasks: a. Create a FractionException class. The class contains a Fraction object and a string message explaining the reason for the exception. Include a constructor that requires values for the Fraction and the message. Also include a function that displays the message. b. Modify each Fraction class constructor and data entry function so that it throws a FractionException whenever a client attempts to instantiate a Fraction with a zero denominator. c. Write a main()function that asks the user to enter values for four Fractions. If the user attempts to create a Fraction with a zero denominator, catch the exception, display a message, and force the Fraction to 0 / 1. Display the four Fraction objects. Save the file as FractionException1.cpp.
The C++ exception class includes the function _______________.
Chapter 16 Solutions
STARTING OUT WITH C++ MPL
Ch. 16.1 - Prob. 16.1CPCh. 16.1 - Prob. 16.2CPCh. 16.1 - Prob. 16.3CPCh. 16.1 - Prob. 16.4CPCh. 16.1 - Prob. 16.5CPCh. 16.2 - Prob. 16.6CPCh. 16.2 - The function int minPosition(int arr[ ], int size)...Ch. 16.2 - What must you be sure of when passing a class...Ch. 16.2 - Prob. 16.9CPCh. 16.4 - Prob. 16.10CP
Ch. 16.4 - In the following Rectangle class declaration, the...Ch. 16 - The line containing a throw statement is known as...Ch. 16 - Prob. 2RQECh. 16 - Prob. 3RQECh. 16 - Prob. 4RQECh. 16 - The beginning of a template is marked by a(n)...Ch. 16 - Prob. 6RQECh. 16 - A(n)______ container organizes data in a...Ch. 16 - Prob. 8RQECh. 16 - Prob. 9RQECh. 16 - Prob. 10RQECh. 16 - Write a function template that takes a generic...Ch. 16 - Write a function template that is capable of...Ch. 16 - Describe what will happen if you call the function...Ch. 16 - Prob. 14RQECh. 16 - Each of the following declarations or code...Ch. 16 - Prob. 16RQECh. 16 - String Bound Exceptions Write a class BCheckString...Ch. 16 - Prob. 2PCCh. 16 - Prob. 3PCCh. 16 - Sequence Accumulation Write n function T...Ch. 16 - Rotate Left The two sets of output below show the...Ch. 16 - Template Reversal Write a template function that...Ch. 16 - SimpleVector Modification Modify the SimpleVector...Ch. 16 - Prob. 8PCCh. 16 - Sortabl eVector Class Template Write a class...Ch. 16 - Prob. 10PCCh. 16 - Word Transformers Modification Modify Program...Ch. 16 - Prob. 12PC
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
- in 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_forwardCUSTOM EXCEPTION 1 Donor Eligibility Write a C++ program to handle the exception. Read all the details and check for the eligibilty of the donors. Conditions: Age must be greater than 17. Minimum weight should be greater than 44 kg. Maximum amount of blood can be drawn is 350ml. if any of the conditions are not met then throw an exceptibn Refer the sample input/output below. Input and Output Format: Refer sample input and output for formatting specifications. All text in bold corresponds to input and the rest corresponds to output. [All text in bold corresponds to input and P Type here to searcharrow_forwardAny number of arguments may be used in a catch block.arrow_forward
- C# (FormatExceptions) Create an app that inputs miles driven and gallons used, and calculates miles per gallon. The example should use exception handling to process the FormatExceptions that occur when converting the input strings to doubles. If invalid data is entered, display a message informing the user.arrow_forwardC++ PROGRAM EXCEPTION HANDLING Write a program with a function that takes a string as an argument from user which displays the string in descending lexicographical order (dictionary order). Suppose user enters ahmad then output should be mhdaa. The program should contain at least 5 characters. If there are less than 5 characters, then your program must throw an integer exception. If the user enters only numeric characters, then your program must also throw an integer exception. Write appropriate catch blocks for exceptions.arrow_forwardT/F 6) Exception is a component of the class library of both java.lang and java.io, but IOException is exclusive to java.ioarrow_forward
- Exception handling to detect input string vs. int C++ The given program reads a list of single-word first names and ages (ending with -1), and outputs that list with the age incremented. The program fails and throws an exception if the second input on a line is a string rather than an int. At FIXME in the code, add a try/catch statement to catch ios_base::failure, and output 0 for the age. Ex: If the input is: Lee 18 Lua 21 Mary Beth 19 Stu 33 -1 then the output is: Lee 19 Lua 22 Mary 0 Stu 34 #include <string>#include <iostream> using namespace std; int main() { string inputName; int age; // Set exception mask for cin stream cin.exceptions(ios::failbit); cin >> inputName; while(inputName != "-1") { // FIXME: The following line will throw an ios_base::failure. // Insert a try/catch statement to catch the exception. // Clear cin's failbit to put cin in a useable state. cin >> age; cout << inputName…arrow_forwardThere is no limit to the number of arguments that may be used in a catch block.arrow_forwardin pythonarrow_forward
- What happens when a raise statement is encountered in a function? O The code executes the next line in the function. O The raise exception is printed immediately. O An exception is immediately executed by the function returning -1. O The function is exited with no return.arrow_forwardin 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_forward1. Exceptions Quiz by CodeChum Admin Write a program that accepts an integer N which serves as the size of an array. Ask for N number of elements. After, continuously ask for user input index. Mark the element at that index as zero. If the user gives an invalid index, throw the appropriate exception and print "Illegal index!". The program ends once an exception is thrown or once the array contains only zeroes. Lastly, print the array elements separated by space. Inputs 1. Multiple lines of integerarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher: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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning