Question: C++ Step 4 Exceptions Create an exception class called CharException to be thrown in the equals function that takes an int as a parameter. You

C++

Step 4 Exceptions

Create an exception class called CharException to be thrown in the equals function that takes an int as a parameter. You should check the range of the int to make sure it is a valid readable character. Basically if the parameter is less than 32 or greater than 127 you want to throw a CharException with the message "Invalid Character".

C++

Use public inheritance to derive your CharException class from exception. Override the virtual function what (const char *what()) so that it returns the message "Invalid Character". Use the what function to display the error message. Below is and image of main and it's output to give you an idea of how the class should work:FinallyCreate a BigDecimalException class that is derived from the CharException class. You should throw this exception anytime that a character is being set that is not a valid character (a digit or a decimal). You should also throw this exception if more than one decimal is being set.At this point I am not going to give you many specifics on how to implement this. I will only say that you are to use inheritance. No matter how you implement this class please have good reasoning for doing so. It is time for all of us to start using what we have learned to formulate our own ideas.Important:For this assignment I expect that you will use good coding practices. This means that whenever possible you should create one code path. Having code duplications will be frowned upon and may result in a point reduction in your grade.

int main() { Char ch('A'); Char c('B'); cout << ch.add(c) << endl; cout << ch.toChar() << " In Hex: " << ch.toHexString(); cout << ch.toChar() << " In Decimal " << ch.toInt(); try { cout << "Try to set 140 as character" << endl; ch.equals(140); cout << ch.toChar() << endl; } catch (CharException *ce) { cout << ce->what() << endl; } return 0; } 

AB A In Hex: 41 A In Decimal 65 Try to set 140 as character Invalid Character Press any key to continue . . .

Finally

Create a BigDecimalException class that is derived from the CharException class. You should throw this exception anytime that a character is being set that is not a valid character (a digit or a decimal). You should also throw this exception if more than one decimal is being set.

At this point I am not going to give you many specifics on how to implement this. I will only say that you are to use inheritance. No matter how you implement this class please have good reasoning for doing so. It is time for all of us to start using what we have learned to formulate our own ideas.

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!