Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write in C++ Do the following problem. For assignment submission, use the format

ID: 3819100 • Letter: W

Question

Write in C++

Do the following problem. For assignment submission, use the format listed in the syllabus. Use comments in your code (3 points will be deducted from each problem missing comments) 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!" Write a C++ program to test the class tornadoException.

Explanation / Answer

class tornadoException
{
public:
tornadoException()
{
message = "Tornado: Take cover immediately!";
}
tornadoException(int m)
{
miles = m;
message = "Tornado: ";
cout << m << "miles away; and approaching!" << endl;
}
string what()
{
return message;
}
private:
int miles;
string message;
};

int main()
{
int distance;

try
{
cout << "Enter distance";
cin >> distance;
cout << endl;

if (distance == 0)
throw tornadoException();
  
}
catch (tornadoException me)
{
cout << me.what() << endl;
}
  
  
system("pause");
}

Please rate! Thank You!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote