Question: This exercise is the same as Programming Exercise 2, except that the exceptions should be derived from a base class (itself derived from logic_error) that
This exercise is the same as Programming Exercise 2, except that the exceptions should be derived from a base class (itself derived from logic_error) that stores the two argument values, the exceptions should have a method that reports these values as well as the function name, and a single catch block that catches the base-class exemption should be used for both exceptions, with either exception causing the loop to terminate.
Data from Programming Exercise 2
Modify Listing 15.11 so that the two exception types are classes derived from the logic_error class provided by the


Listing 15.11 error4.cpp //error4.cpp - using exception classes #include #include // or math.h, unix users may need -1m flag #include "exc_mean.h" // function prototypes double hmean (double a, double b); double gmean (double a, double b); int main() { using std::cout; using std::cin; using std::endl; double x, y, z; cout < < "Enter two numbers: "; while (cin >> x >> y) { try { // start of try block z hmean (x,y); cout < < "Harmonic mean of " < < x < < " and " < < y < < " is " < < Z < < endl; cout < < "Geometric mean of " < < x < < " and " < < y " is " < < gmean (x, y) < < endl; cout < < "Enter next set of numbers : "; }// end of try block catch (bad_hmean & bg) { bg.mesg(); cout < < "Try again. "; // start of catch block
Step by Step Solution
3.36 Rating (162 Votes )
There are 3 Steps involved in it
include include or mathh unix users may need lm flag in... View full answer
Get step-by-step solutions from verified subject matter experts
