Languages home 8.5: LAB Exception handling to detect input string vs. int 8.5 LAB: Exception handling...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Languages home 8.5: LAB Exception handling to detect input string vs. int 8.5 LAB: Exception handling to detect input string vs. Int 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 3001164 LAB ACTIVITY 1 #include <string> 2 #include <iostream> 3 4 using namespace std;; 5 6 int main() ( 7 D 9 8.5.1. LAB Exception handling to detect input string vs. int 10 11 12 13 14 15 16 17 string inputName; int age; // Set exception mask for cin stream cin.exceptions (los: fallbit); main.cpp cin >> inputName; while(inputName 1-"-1") ( // FIXME: The following Line will throw an tos base::fallure. 11 Insert o try/catch statement to catch the exception. Clear cin's fallbit to put cin in a useable state. 18 cin >> age; 0/10 Load default template.... Languages home 8.5: LAB Exception handling to detect input string vs. int 8.5 LAB: Exception handling to detect input string vs. Int 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 3001164 LAB ACTIVITY 1 #include <string> 2 #include <iostream> 3 4 using namespace std;; 5 6 int main() ( 7 D 9 8.5.1. LAB Exception handling to detect input string vs. int 10 11 12 13 14 15 16 17 string inputName; int age; // Set exception mask for cin stream cin.exceptions (los: fallbit); main.cpp cin >> inputName; while(inputName 1-"-1") ( // FIXME: The following Line will throw an tos base::fallure. 11 Insert o try/catch statement to catch the exception. Clear cin's fallbit to put cin in a useable state. 18 cin >> age; 0/10 Load default template....
Expert Answer:
Answer rating: 100% (QA)
To catch the iosbasefailure exception and handle it by outputting 0 for the age ... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
Mitchell's tax service is looking to uncover more value for customers by improving the way appoitments are booked with a new software system. It will automate the system and help save the
-
A researcher wanted to find out if there was difference between older movie goers and younger movie goers with respect to their estimates of a successful actors income. The researcher first...
-
It is initially at 25\deg C. The warehouse is desired to be cooled to 5\deg C. The heat transferred from the external environment to the tank is 1.2 kW. Accordingly, a cooling system with H kW power...
-
Question 2: The following term structure of spot rates is prevailing in the economy: Horizon (years) 1 2 3 Yield (%) 3 4 5 This means you can trade zero coupon bonds with face values of $1000 at...
-
Give the possible term symbols for (a) Sc [Ar] 3d14s2, (b) Br [AI'] 3d 104s24p5.
-
Condensed income statements for PCO and its 75-percent-owned subsidiary, SCO, appear below: Intercompany sales amounted to $400,000, unconfirmed intercompany profits in ending inventory are $50,000...
-
A 5-m-diameter parachute of a new design is to be used to transport a load from flight altitude to the ground with an average vertical speed of \(3 \mathrm{~m} / \mathrm{s}\). The total weight of the...
-
The following information is available for the preparation of the governmentwide financial statements for the city of Southern Springs as of April 30, 2012: Cash and cash equivalents, governmental...
-
(a) A wooden sphere with a diameter of d = 0.14 m (density? = 0.40 g/cm3) held under water by a string. What is the tension (in N) in the string? Note: Draw the free body diagram. (Assume the density...
-
The information listed below refers to the employees of Lemonica Company for the year ended December 31, 2016. The wages are separated into the quarters in which they were paid to the individual...
-
Fung is planning for the correct after tax and after inflation real rate of return to use. If inflation will be 1.3%, the average rate of return on his investments will be 4.9%, and the tax rate on...
-
Substitute the value for the probability PN given by equation (11.8), in the Boltzmann expression for the entropy, namely S=-kP., log PN.1 N to show that for the grand canonical ensemble...
-
.. Solve the following equation by factoring: x(x-11) + 28 = 0
-
An investor purchases an inflation protection security with a par value of R200000 and a coupon rate of 4% and the annual inflation is 3% what would be the coupon payment on this security coupon rate...
-
69. Newton's law of gravitational attraction states that if two bodies are at a distance r apart, then the force F exerted by one body on the other is given by F(r) = k p2 where k is a positive...
-
The data in the following table were obtained in a travel time study on a section of highway with length 1.5 km, using the moving-vehicle technique. Determine average travel time, volume, and speed...
-
Use the molecular orbital diagram shown to determine which of the following is most stable. Atomic orbitals 2p ON O B C 25 24 B 2 + C1 Molecular orbitals Gip It ip Otp TU P B, C, N Atomic orbitals 24...
-
A heat engine has a heat input of 3 Ã 104 Btu/h and a thermal efficiency of 40 percent. Calculate the power it will produce, in hp. Source 3 x 10 Btu/h 40% HE Sink
-
Write a fragment of code that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterwards.
-
Create an abstract class PayCalculator that has an attribute payRate given in dollars per hour. The class should also have a method computePay(hours) that returns the pay for a given amount of time.
-
Do Programming Project 17 from Chapter 4, the Edoc calculator, except use a recursive function to calculate or help you calculate the maximum amount of experience points you can earn. Project 17 from...
-
Companies are facing a great amount of change in every facet of their operations today. To remain competitive, companies must keep abreast of current developments in several areas. You recently got...
-
For each of the situations listed, identify the primary standard from the IMA Statement of Ethical Professional Practice that is violated (competence, confidentiality, integrity, or credibility.)...
-
Sustainability involves more than just the impact of actions on the environment. The triple bottom line recognizes that a company has to measure its impact on its triple bottom line for its long-term...
Study smarter with the SolutionInn App