Question: Define an exception class called tornadoException. The class should have two constructors, including the default constructor. If the exception is thrown with the default constructor,

Define an exception class called tornadoException. The class should have two constructors, including the default constructor. If the exception is thrown with the default constructor, the method what should return "Tornado: Take cover immediately!". The other constructor has a single parameter, say, m, of the int type. If the exception is thrown with this constructor, the method what should return "Tornado: m miles away; and approaching!". You decide what value of m should be used to trigger the non-default warning. Write a program to test this class.

Here is a standard way to create the message using the integer parameter. There are nonstandard ways to do this which are compiler-dependent. Please use this method for this program so you will know what to do if you use a compiler that does not support one of the nonstandard methods.

#include // Include the stringstream library #include using namespace std; int main() { double balance = 250.75; // Declare a stringstream buffer variable stringstream ss; string message; // Stream your output to the stringstream buffer ss << "You have a balance of: $" << balance; // Convert the characters in the stringstream buffer to a string message = ss.str(); cout << message << endl; return 0; }

Turn in your tornadoException.h file and your test program. Also turn in one or more screen shots showing the results of your testing.

Once completed you will demonstrate that you can

Construct a user-defined exception class.

Throw an exception which generates a default message

Throw an exception which generates a message from a parameter sent through an exception object.

Handle an exception using catch blocks.

Generate a string which incorporates a numeric value using the stringstream library.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!