Question: Listing 15.16 uses two catch blocks after each try block so that the nbad_index exception leads to the label_val() method being invoked. Modify the program
Listing 15.16 uses two catch blocks after each try block so that the nbad_index exception leads to the label_val() method being invoked. Modify the program so that it uses a single catch block after each try block and uses RTTI to handle invoking label_val() only when appropriate.

![std::cout; using std::cin; using std::endl; double vals1 [12] = { }; nested](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1662/1/1/4/2576311d9d1a4cf91662114258421.jpg)
Here is the output of the program in Listings 15.14, 15.15, and 15.16:
First try block:
Year = 2011
1220 1100 1122 2212 1232 2334
2884 2393 3302 2922 3002 3544
Year = 2012
Label = Blogstar
12 11 22 21 32 34
28 29 33 29 32 35
Index error in LabeledSales object
Company: Blogstar
bad index: 12
Next try block:
Index error in Sales object
bad index: 20
done
Listing 15.16 use_sales.cpp // use_sales.cpp #include #include "sales.h" int main() { using std::cout; using std::cin; using std::endl; double vals1 [12] = { }; nested exceptions 1220, 1100, 1122, 2212, 1232, 2334, 2884, 2393, 3302, 2922, 3002, 3544 double vals2 [12] = { 12, 11, 22, 21, 32, 34, 28, 29, 33, 29, 32, 35 }; Sales sales1 (2011, valsi, 12); Labeledsales sales2 ("Blogstar", 2012, vals2, 12); cout < < "First try block: "; try int i; cout < < "Year = " < < sales1. Year () < < endl; for (i = 0; i < 12; ++1) { cout < < salesl [i] < < ; if (1 6 = 5) cout < < endl; } cout < < "Year = " < < sales2. Year() < < endl; cout < < "Label = " < < sales2.Label() < < endl; for (i = 0; i
Step by Step Solution
3.42 Rating (161 Votes )
There are 3 Steps involved in it
include include using namespace std class Sales public enum MONTHS 12 class badindex public logicerr... View full answer
Get step-by-step solutions from verified subject matter experts
