Question
I need help with this C++ homework. I just need it done in 1 file: Quiz.h which is derived from a class NAquestion and base
I need help with this C++ homework. I just need it done in 1 file: Quiz.h which is derived from a class NAquestion and base class Question. so I will post these as well. I don't need the main.cpp.
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 elemType objects. Also, it has two accessors: getScore, and getQuestion. getQuestions 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 elemType pointer will be stored, and the elemType 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 elemType pointer argument; or (3) If the position in the array contains already a elemType (i.e. not null), delete that elemType from memory; then update that pointer with the elemType pointer argument. resetQuestions will remove from memory the existing elemType pointed by questions array and set all the pointers to null.
//Question (Base) class: #include
class Question { public: Question(); Question(string quest); void setText(string quest); string getText() const; void setPoints(int points); int getPoints() const; void display() const; private: string text; int points; };
=====================================================
//Question.cpp:
#include "Question.h" #include
using namespace std;
Question::Question(): text(""), points(1){} Question::Question(string quest): text(quest),points(1){} void Question::setText(string quest){ text = quest; } string Question::getText() const{return text;} void Question::setPoints(int points){ this->points = points; } int Question::getPoints() const{return points; } void Question::display() const{ cout
//NAquestion.h: #include "Question.cpp" class NAquestion : public Question { // the two member variable of this class. float correctAnswerMin; float correctAnswerMax; public: //one nonparameterized constructor and one parameterized constructor. NAquestion(); NAquestion(string text, float min, float max); void setCorrectAnswer(float min, float max); //method that returns the getCorrectAnswerMin float getCorrectAnswerMin() const; //method that returns the getCorrectAnswerMax float getCorrectAnswerMax() const; //isCorrect() method returns points of the question if the variable's m value is between correctAnswerMax and correctAnswerMin int isCorrect(float m); //+ operator overloading method int operator +(const int value); friend ostream& operator= min) { correctAnswerMax = max; correctAnswerMin = min; } } void NAquestion::setCorrectAnswer(float min, float max) { if(max >= min) // set the values of the correctAnswerMax and correctAnswerMin if given min is less than max. { correctAnswerMin = min; correctAnswerMax = max; } } float NAquestion::getCorrectAnswerMin() const { return correctAnswerMin; } float NAquestion::getCorrectAnswerMax() const { return correctAnswerMax; } int NAquestion::isCorrect(float m) { int i = 0; if(m > getCorrectAnswerMin() && m Quiz class Create a class template for a quiz. Quiz -score: double -questions[5]: elemType* +getScore) const: double +setQuestion(int, elem Type *): void +getQuestion(int) const: elem Type tresetQuestions(): void +startAttempt(): void +Quiz() This class template uses elemType to represent the parameter type. This class has a function called startAttempt, which will display (use the overloaded insertion operator) 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 obtained points. At the end, calculate the score of the attempt (= obtained points / total number of points), 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 elemType, count that question's point in the score, display, and ask for user input. (3) If all positions in the array contains a null value, startAttempt do nothing. Quiz class Create a class template for a quiz. Quiz -score: double -questions[5]: elemType* +getScore) const: double +setQuestion(int, elem Type *): void +getQuestion(int) const: elem Type tresetQuestions(): void +startAttempt(): void +Quiz() This class template uses elemType to represent the parameter type. This class has a function called startAttempt, which will display (use the overloaded insertion operator) 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 obtained points. At the end, calculate the score of the attempt (= obtained points / total number of points), 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 elemType, count that question's point in the score, display, and ask for user input. (3) If all positions in the array contains a null value, startAttempt do nothing
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