Question
Please I need help with this question. It should be written in C++, the main is already given, and the Question class is already coded.
Please I need help with this question. It should be written in C++, the main is already given, and the Question class is already coded. I just need the NAquestion.h and NAquestion.cpp files and Quiz.h and Quiz.cpp files. I will also post the main and Question class. thank you
Question.h:
#ifndef QUESTION_H #define QUESTION_H #include using namespace std;
// defining class in Question.h file class Question { private: // private string variable string text; public: // public methods listed in the given class diagram void setText(string t); string getText() const; void display() const; Question(); Question(string); }; #endif // QUESTION_H
Question.cpp:
#include "Question.h" // including header file
// defining setText() to set text of question void Question::setText(string t) { text = t; } // defining getText() to get text of question string Question::getText() const { return text; } // defining display() to display text of question void Question::display() const { cout
Main:
#include #include "Quiz.h"
int main() { std::cout
Quiz quiz1; NAquestion* pq1 = new NAquestion("...."); NAquestion* pq2 = new NAquestion("...."); NAquestion* pq3 = new NAquestion("....");
quiz1.setQuestion(0, pq1); quiz1.setQuestion(0, pq1); quiz1.setQuestion(0, pq1);
quiz1.startAttempt(); quiz1.resetQuestion(); }
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). NAquestion -correctAnswer Min: float -correctAnswerMax: float +setCorrectAnswer(float,float): void +getCorrectAnswer Min() const: float +getCorrectAnswerMax() const: float +isCorrect(float) const: bool +NAquestion() +NAquestion(string.float,float) As seen in the diagram, NA question has two private member variables: correctAnswer Min, and correctAnswerMax. correctAnswer Min and correct AnswerMax define the range of values accepted as a correct answer. Thus, correctAnswer Min is less than or equal to correctAnswer Max. Also, it has one mutator: setCorrectAnswer; and two accessors: getCorrectAnswer Min, and getCorrect AnswerMax. In setCorrectAnswer function, the first argument is the value for correct AnswerMin, and the second argument is the value for correct AnswerMax. Therefore, if the first argument's value is not less than or equal to second argument's value, do not change the values of correctAnswerMin and correctAnswer Max. In addition, this class has a function called isCorrect, which given a float argument, it will return whether that float argument is between correct Answer Min and correct AnswerMax (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, correct AnswerMin, and correctAnswerMaxStep 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