Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

solve it with C++ language Lab Objectives: You will practice in this lab with inheritance A Question Bank! In this exercise, you will implement a

solve it with C++ language
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Lab Objectives: You will practice in this lab with inheritance 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 MathQuestion MCQ 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: W/ prints out to the console the question text and the number of points void ask() const W returns the question answer string get_answer() const // returns the question points dint 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 (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 choice Implement also a Destructor to deallocate any dynamically allocated memory Public Functions Override the following functions from the parent class: void ask() const This function must print the question text followed by the choices. Each choice must be preceded by its index bool is correct(string answer) const 06 This function must return true if the received answer equals the question answer or if it equals the index of the correct answer Math Question Class Create a class named MathQuestion in files math_question.h and math_question.cpp. This class represents an addition, subtraction or multiplication question between two random numbers. The class must inherit from class Question using public inheritance Constructor The class must have only one constructor. This constructor must receive as arguments: . the question points . an operator (.'-'or) and the maximum number of digits in the numbers used in the question Generate two random numbers (considering the maximum number of digits received as an argument) and use them with the received operator to set the question text and answer of the received operator is not valid, output an error message and exit the program To concatenate a string and an integer, you can use the to, string function. For example: string strato atring(ne) years old stores "lam 20 years old" in ste If the value stored in age is 20 Public Functions Do not add any public functions beside the constructor and do not override any of the public functions in the parent class Main Implement a simple program in test.cpp to test the three classes you have implemented. Your program must perform the following: Create at least one Question object, one MathQuestion object and one McQ object. Allow the user to answer the created questions, Display the total points for the questions the user answered correctly. The following is a sample run of the program: What is the capital of Jordan? (use Title Case) [10 points) Irbid WRONG! Note. You will notice in this lab that you will do a lot of copying and pasting. This is bad. You will be able to solve this issue using polymorphism once you learn about it. If you know about polymorphism and would like to use it to make your main) cleaner, then go ahead

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

Students also viewed these Databases questions

Question

Excel caculation on cascade mental health clinic

Answered: 1 week ago