Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need to write this code in C++, it should have two separate files: Quiz.h and Quiz.cpp. Quiz class Create a class for a quiz.
I need to write this code in C++, it should have two separate files: Quiz.h and Quiz.cpp.
Quiz class Create a class for a quiz. Quiz -score: double -questions[4]: NAquestion* +getScore() const: double +setQuestion(int,NAQuestion*): void +getQuestion(int) const: NAquestion* tresetQuestions(): void +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 questions, which is an array of pointers to NAquestion objects. Also, it has two accessors: getScore, and getQuestion. 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. There is no mutator function for score. 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 NAquestion (i.e. not null), delete that NAquestion from memory; then update that pointer with the NAquestion pointer argument. resetQuestions will remove from memory the existing NAquestions pointed by questions array and set all the pointers to null. (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 NAquestion (i.e. not null), delete that NAquestion from memory; then update that pointer with the NAquestion pointer argument. resetQuestions will remove from memory the existing NAquestions pointed by questions array and set all the pointers to null. 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 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 NAquestion, count that question in the score, display, and ask for user input. (3) If all positions in the array contains a null value, startAttempt do nothing. Finally, it has a no-argument constructor which initialize the pointers in the question array to null. Class files Classes must be separated in a .h file (header), and a .cpp (source code). Quiz class Create a class for a quiz. Quiz -score: double -questions[4]: NAquestion* +getScore() const: double +setQuestion(int,NAQuestion*): void +getQuestion(int) const: NAquestion* tresetQuestions(): void +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 questions, which is an array of pointers to NAquestion objects. Also, it has two accessors: getScore, and getQuestion. 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. There is no mutator function for score. 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 NAquestion (i.e. not null), delete that NAquestion from memory; then update that pointer with the NAquestion pointer argument. resetQuestions will remove from memory the existing NAquestions pointed by questions array and set all the pointers to null. (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 NAquestion (i.e. not null), delete that NAquestion from memory; then update that pointer with the NAquestion pointer argument. resetQuestions will remove from memory the existing NAquestions pointed by questions array and set all the pointers to null. 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 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 NAquestion, count that question in the score, display, and ask for user input. (3) If all positions in the array contains a null value, startAttempt do nothing. Finally, it has a no-argument constructor which initialize the pointers in the question array to null. Class files Classes must be separated in a .h file (header), and a .cpp (source code)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