Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A Question Bank! In this exercise, you will implement a hierarchy of three classes that represent exam questions. The classes and their relationship are depicted

A Question Bank!
In this exercise, you will implement a hierarchy of three classes that represent exam questions. The classes and their relationship are depicted in the following UML class diagram:
Question Class
Data Members
Each question stores its text and answer (as strings) and its number of points (as an unsigned integer).
Constructor
The class must have only one constructor. This constructor must receive the question text, answer and points as arguments.
Public Functions
Beside the constructor, the class must have the following functions:
// prints out to the console the question text and the number of points void ask() const
// returns the question answer
string get_answer () const
// returns the question points.
int get_points ) const
// checks if the received answer equals the question answer
bool is_correct(string answer) const
MCQ Class
Create a class named MCQ in files mcq.h and mcq.cpp. This class represents a multiple-choice question (MCQ).
The class must inherit from class Question using public inheritance.
Data Members
Beside the question text, answer and points, each MCQ stores
an array of choices (each choice is a string),
the size of the array (i.e. the number of available choices) and
the index of the correct answer
Constructors and Destructors
The class must have only two constructors. This first constructor must be a parameterized constructor that receives as arguments
the question text,
the question points,
the array of choices and its size and
the index of the correct answer.
This constructor sets the question answer based on the given array of choices and index of the correct answer.
The second constructor is a copy constructor.
Make sure that the two constructors do a deep copy of the array of choices.
Implement also a Destructor to deallocate any dynamically allocated memory.
Public functions
Override the following function:
void ask() const
This function must print the question text followed by the choices. Each choice must be preceded by its index.
Main
Implement a simple program in test.cpp to test the classes you have implemented. Your program must perform the following:
Create at least two Question object and two MCQ object.
Allow the user to answer the created questions.
Display the total points for the questions the user answered correctly.
This is a sample output:
What is the capital of Jordan? (use Title Case)[10 points]
Irbid
WRONG!
Shuffling Choices
Implement the function void shuffle(MCQ& question) that shuffles the choices in the given McQ as follows:
Repeat 100 times the following:
Pick two random indices from the question choices array.
Swap the the two array elements.
Update the correct answer index if necessary.
Make this function a friend of class MCQ and modify your main() to test this function.
Optional. This shuffing algorthm is not a good way to shuffle. If you are interested read about Knuth Shuffle, which is simple and does the job well
*you must give me 5 files for this program
image text in transcribed

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

Present main arguments for and against the computer metaphor.

Answered: 1 week ago