Question: Create a class for a question. Question -text: string +setText(string): void +getText() const: string +display() const: void +Question() +Question(string) As seen in the diagram, Question

Create a class for a question.

Question

-text: string

+setText(string): void

+getText() const: string

+display() const: void

+Question()

+Question(string)

As seen in the diagram, Question has 1 private member variable: text. Also, it has one mutator: setText; and one accessor: getText.

Also, the class has a display function which shows the questions text.

Finally, it has 2 constructors: a no-argument constructor, and a one-argument constructor whose argument is the questions text. The one-argument constructor will only initialize the text of the question.

Multiple-choice question class

Create a derived class for a multiple-choice question from the question base class. Use public as the access specifier for the inheritance.

MCquestion

+choices: string[4]

-correctAnswer: int

+setCorrectAnswer(int): void

+getCorrectAnswer() const: int

+isCorrect(int) const: bool

+display() const: void

+MCquestion()

+MCquestion(string)

As seen in the diagram, MC question has one private member variable: correctAnswer; and a public member array, choices. Choices is an array that stores the possible answer for a questions answer. This array contains 4 strings. correctAnswer stores the position in the array which contains the correct answer.

Also, it has one mutators: setCorrectAnswer; and one accessor: getCorrectAnswer. In setCorrectAnswer function, do a validation. If the arguments value is not between 0-3 (inclusive), do not change the correct answer value.

In addition, this class has a function called isCorrect, which given an integer argument, it will compare it with the correctAnswer, and returns whether the values are the same (true or false). Before doing the comparison, decrease the integer argument by one (-1). This is because the choices are stored in a 0-based index array, and the choices will be displayed in a 1-based index list.

Also, override the display function to show the question and the choices (with an index, 1-4).

Finally, it has 2 constructors: a no-argument constructor, and a one-argument constructor whose argument is the questions text. The one-argument constructor will only initialize the text of the question.

Short-Answer question class

Create a derived class for a short-answer question from the question base class. Use public as the access specifier for the inheritance.

SAquestion

-correctAnswer: string

+setCorrectAnswer(string): void

+getCorrectAnswer() const: string

+isCorrect(string) const: bool

+SAquestion()

+SAquestion(string,string)

As seen in the diagram, SA question has one private member variable: correctAnswer, which stores the text of the correct answer.

Also, it has one mutators: setCorrectAnswer; and one accessor: getCorrectAnswer. In setCorrectAnswer function, do a validation. If the arguments length is not greater than zero (>0), do not change the correct answer text.

In addition, this class has a function called isCorrect, which given a string argument, it will compare it with the correctAnswer, and returns whether the values are the same (true or false).

Finally, it has 2 constructors: a no-argument constructor, and a two-argument constructor. The two-argument constructor will initialize the text of the question and the answer of the question.

Quiz class

Create a class for a quiz.

Quiz

-score: double

+question01: MCquestion

+question02: SAquestion

+question03: MCquestion

+question04: SAquestion

+getScore() const: double

+startAttempt(): void

+Quiz()

As seen in the diagram, Quiz has one private member variable: score, which stores the score after an attempt. Also, it contains question01, question03 which are MCquestion objects; and question 02, question04 which are SAquestion objects.

Also, it has one accessor: getScore. There is no mutator function for score.

In addition, this class has a function called startAttempt, which will display each of the questions and ask for user input in each question. After each user input, determine and show whether users answer was correct, and count the number of right answers. At the end, calculate the score of the attempt (= right answers / number of question), a value between 0.00-100.00, display and store it in score.

Finally, it has a no-argument constructor.

Class files

Classes must be separated in a .h file (header), and a .cpp (source code).

The main program

Use that class in a main program that creates one quiz object which contains 2 multiple-choice questions, and 2 short-answer questions.

You can get examples of multiple choices questions from Multiple-choice trivia questions and examples of short-answer questions from General Trivia questions.

Then, execute startAttempt in the quiz object.

USING C++ ONLY. PLEASE INCLUDE OUTPUT

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!