Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Code in C++ Question class Create a class for a question. 1 Question -text: string +setText(string): void +getTexti) const: string +display() const: void +Question +Question(string)
Code in C++
Question class Create a class for a question. 1 Question -text: string +setText(string): void +getTexti) const: string +display() const: void +Question +Question(string) Function/constructor description: Quiz -score: double questions[4]: NAquestion* +getScorel) const: double +setQuestioolint.NAQuestion *): void +getQuestion(int) const: NAquestion +reset Questions(): void +startAttempt(): void +Quiz) setText, text's mutator. getText, text's accessor. display, shows the question's text. Question, initializes text as an empty string. Question(string), initialize text with the constructor argument. As seen in the diagram, Quiz has one private member variable: score, which stores the score after an attempt. Also, it contains questions, which is an array of pointers to Naguestion objects. Also, it has two accessors: getscere, and getQuestions getQuestion's integer argument is the position of the pointer in the array. Given the position in the array, if it points to an object, returns the pointer to that object; otherwise, returns null. Also, if position is less than 0 or greater than 3, return null. Numeric-Answer question class Create a derived class for a numeric-answer question from the question base class. Use public as the access specifier for the inheritance. There is no mutator function for score. NAquestion -CorrectAnswer Min: float -correstAnswerMax: float +set CorrectAnswer{float.float): void +get Correct Answer Mial const: float +getCorrect AnswerMaxl) const: float +iscarrest(float) const: bool +NAquestion +NAquestion(string.float,float) setQuestion is the mutator for each of the pointers to the questions. The integer argument is the position where a NAquestion pointer will be stored, and the NAquestion pointer is the object reference to store. This function will do some validations: (1) If position is less than 0 or greater than 3, do nothing. (2) If the position in the array contains a null value, update that pointer with the NAquestion pointer argument; or (3) If the position in the array contains already a Naguestion (ie, not null), delete that Naguestion from memory; then update that pointer with the NAguestion pointer argument. Leset Questions will remove from memory the existing NAguestions pointed by questions array and set all the pointers to null. As seen in the diagram, NA question has two private member variables: correct AnswerMin and SorrectAnswer Max CorrectAnswer Min and Sorrect Answer Max define the range of values accepted as a correct answer. Thus, SecrestAnswer Min is less than or equal to correctApsver Max Also, it has one mutator: setCorrectAnswer, and two accessors: get CorrestAnswer Mic, and get CorrestAnswerMax- In setForcestAnswer function, the first argument is the value for correctAnswermin, and the second argument is the value for secrestAnswer Max. Therefore, if the first argument's value is not less than or equal to second argument's value, do not change the values of correct AnswerMin and correct Answer Max In addition, this class has a function called iscecrest, which given a float argument, it will return whether that float argument is between correctApsver Min and correctAnswerMax (true or false). Finally, it has 2 constructors: a no-argument constructor, and a three-argument constructor. The three-argument constructor will initialize the text of the question, correctAnswer Min and correct Answer Max In addition, this class has a function called startAttenet, which will display each of the questions and ask for user input in each question. After each user input, determine and show whether user's 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. This function will do some validations: (1) If a position in the questions array contains a null value, does not count that question in the score, and do not try to display it. (2) If a position in the array contains a Naguestion, count that question in the score, display, and ask for user input. (3) If all positions in the array contains a null value, startAttenet do nothing. Question class Create a class for a question. 1 Question -text: string +setText(string): void +getTexti) const: string +display() const: void +Question +Question(string) Function/constructor description: Quiz -score: double questions[4]: NAquestion* +getScorel) const: double +setQuestioolint.NAQuestion *): void +getQuestion(int) const: NAquestion +reset Questions(): void +startAttempt(): void +Quiz) setText, text's mutator. getText, text's accessor. display, shows the question's text. Question, initializes text as an empty string. Question(string), initialize text with the constructor argument. As seen in the diagram, Quiz has one private member variable: score, which stores the score after an attempt. Also, it contains questions, which is an array of pointers to Naguestion objects. Also, it has two accessors: getscere, and getQuestions getQuestion's integer argument is the position of the pointer in the array. Given the position in the array, if it points to an object, returns the pointer to that object; otherwise, returns null. Also, if position is less than 0 or greater than 3, return null. Numeric-Answer question class Create a derived class for a numeric-answer question from the question base class. Use public as the access specifier for the inheritance. There is no mutator function for score. NAquestion -CorrectAnswer Min: float -correstAnswerMax: float +set CorrectAnswer{float.float): void +get Correct Answer Mial const: float +getCorrect AnswerMaxl) const: float +iscarrest(float) const: bool +NAquestion +NAquestion(string.float,float) setQuestion is the mutator for each of the pointers to the questions. The integer argument is the position where a NAquestion pointer will be stored, and the NAquestion pointer is the object reference to store. This function will do some validations: (1) If position is less than 0 or greater than 3, do nothing. (2) If the position in the array contains a null value, update that pointer with the NAquestion pointer argument; or (3) If the position in the array contains already a Naguestion (ie, not null), delete that Naguestion from memory; then update that pointer with the NAguestion pointer argument. Leset Questions will remove from memory the existing NAguestions pointed by questions array and set all the pointers to null. As seen in the diagram, NA question has two private member variables: correct AnswerMin and SorrectAnswer Max CorrectAnswer Min and Sorrect Answer Max define the range of values accepted as a correct answer. Thus, SecrestAnswer Min is less than or equal to correctApsver Max Also, it has one mutator: setCorrectAnswer, and two accessors: get CorrestAnswer Mic, and get CorrestAnswerMax- In setForcestAnswer function, the first argument is the value for correctAnswermin, and the second argument is the value for secrestAnswer Max. Therefore, if the first argument's value is not less than or equal to second argument's value, do not change the values of correct AnswerMin and correct Answer Max In addition, this class has a function called iscecrest, which given a float argument, it will return whether that float argument is between correctApsver Min and correctAnswerMax (true or false). Finally, it has 2 constructors: a no-argument constructor, and a three-argument constructor. The three-argument constructor will initialize the text of the question, correctAnswer Min and correct Answer Max In addition, this class has a function called startAttenet, which will display each of the questions and ask for user input in each question. After each user input, determine and show whether user's 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. This function will do some validations: (1) If a position in the questions array contains a null value, does not count that question in the score, and do not try to display it. (2) If a position in the array contains a Naguestion, count that question in the score, display, and ask for user input. (3) If all positions in the array contains a null value, startAttenet do nothingStep 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