Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions