Design guidelines for classes.
Notes:
- Please review the PosInt project very carefully.
- With every class you write for this course (or any course you take with me):
- Include all the constructors that are necessary. Don't be frugal with constructors. They make your classes easier to work with if they are designed well.
- Include all the relevant operators. At the very least insertion and extraction operators where applicable.
- All object arguments are passed by reference.
- the const keyword is used everywhere they are applicable for function and operator parameters AND the functions themselves. (functions that do not change the sate of the class must be marked with the const keyword.)
- (Almost) all member variables are private.
- We do not use protected variables and functions.
- We NEVER print or input data from inside a class, except from an input and output functions
- The class will not provide user interface (switch case, get user choices, and run functions) These belong in in the main function or in a class designed for user interface.
-
Error handling:
- A private member variable _error and four functions is_error(), error(), reset() and error_description() manage the error handing in all objects:
- int or bool private member variable _error: This variable will be set when the class enters an error state.
- In every constructor, mutator, and input function, you will call the is_error() function to check for errors and will set the _error variable to the appropriate value: _error = is_error();
- is_error() will check for errors in the object and return an int (or bool) corresponding to the error state it discovers: 0 for no error.
- error_description will return a string describing the error that has occur
- reset() will reset the object and the error state back to zero
- In main (or any calling function), you may (should) call the object's error( ) function and if it returns a non-zero value, you will call the error_description( ) function of the class and report the error to the user. You do not show the class' erroneous value when there is an error.