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

Need help on follwing program for c++ language. Define an exception class called

ID: 3928087 • Letter: N

Question

Need help on follwing program for c++ language.

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 program to test this class. Please seprate all three files, header file, implementation file, and main file.

Explanation / Answer

// using tornado exceprion
#include <iostream>
#include <exception>

using namespace std;

class tornadoException: public exception
{
tornadoException::tornadoException(){
   return "Tornado: Take cover immediately!";
}  
tornadoException::tornadoException(int m){
   return "Tornado: "+m+" miles away; and approaching!";
}  
};

-------------------------------------------------------------------------------------------------------------------------------------------------------

// main file

#include <iostream>

using namespace std;

int main ()
{
tornadoException myexe;

try
{
throw myexe;
}
catch (exception& e)
{
cout << e << endl;
}
return 0;
}

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