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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.