Answered step by step
Verified Expert Solution
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 getanswer const
returns the question points.
int getpoints const
checks if the received answer equals the question answer
bool iscorrectstring answer const
MCQ Class
Create a class named MCQ in files mcqh and mcqcpp This class represents a multiplechoice 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 ie 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 points
Irbid
WRONG!
Shuffling Choices
Implement the function void shuffleMCQ& question that shuffles the choices in the given McQ as follows:
Repeat 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 files for this program
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started