Question
Instructions: 1. Create the following exception class: InvalidQuestionValueException -message: string +what(): string InvalidQuestionValueException(string m=ERROR: Invalid value. See class documentation.) The constructor will initialize the message
Instructions:
1. Create the following exception class:
InvalidQuestionValueException |
-message: string |
+what(): string InvalidQuestionValueException(string m="ERROR: Invalid value. See class documentation.") |
The constructor will initialize the message variable with the value in parameter m. what() function will return the value in message.
2. Create Class SAquestion
SAquestion |
-text: string -correctAnswer: string -points: int |
+setText(string text): void +setCorrectAnswer(string correctAnswer): void +setPoints(int points): void +getText() const: string +getCorrectAnswer() const: string +getPoints() const: int +isCorrect(string answer) const: bool SAquestion(string text, string correctAnswer, int points) |
Business rules:
- This class represents a short-answer question.
- It stores the text of the question in 'text', which cannot be an empty ("") string.
- It stores the text of the correct answer in 'CorrectAnswer',which cannot be empty ("") string.
- It stores the points of the question in 'points', which can only be a value between 1 and 10 inclusive.
- When trying to set the value of the question's text to an empty string raise an InvalidQuestionValueException with the message "Invalid value: Question's text cannot be empty".
- When trying to set the value of the question's correct answer to an empty string raise an InvalidQuestionValueException with the message "Invalid value: Question's answer cannot be empty".
- When trying to set the points of the question to a value lower than 1 or greater than 10, raise an InvalidQuestionValueException with the message "Invalid value: Question's points must be between 1-10 inclusive".
3. Main projgram
In a try block, create a SAquestion object with an invalid question's text (""), then create another SAquestion object with an invalid question's answer(""), finally, create a third SAquestion object with an invalid question's points (<1 or>10). In a catch block which gets a InvalidQuestionValueException, display the content of the message using what function. To test this program, start with the 3 invalid questions (invalid text, invalid answer, invalid points), and execute it. Then, fix each invalid values, one by one, and look at the different outputs.
4. Files to submit:
- VS project-related files - InvalidQuestionValueException.h and InvalidQuestionValueException.cpp - SAquestion.h and SAquestion.cpp - main file