Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part 1 : Define a new exception class named BadVarException that must inherit from the C + + runtime _ error class. This class will
Part :
Define a new exception class named BadVarException that must inherit
from the C runtimeerror class. This class will capture the error case for a degree about the year and the name.
Part :
Rewrite the class named VariableInt in the previous exercise to generate a "BadVarException"
whenever the caller tries to create the VariableInt object with the following info:
invalid variable name: empty or all blanks
integer value is negative
Part :
Write a function named createVariableObject that will accept the variable name and the value
and it will create a VariableInt object dynamically.
If there is an exception, it will check to see if that is a bad integer value, then it will create a simple Variable object.
If the name is bad, it will return nullptr to the caller.
This function must handle all error cases for invalid name such as empty or blanks or invalid value negative
This function must use handle errors using trycatch the exception.
This function will return the pointer of the newly created VariableInt or Variable object or nullptr depending on the error it receives.
Note: there is no cin and cout in this function. All input and output must be done in the testing function.
Part :
The main function to test createVariableObject:
Create at least objects with different error cases. You can make up your own data. You do not need to get input from the user.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started