I am having trouble with a class project. I am responsible for writing the 2nd part. I dont understand the add function, and I think I may have messed up the displayQuestion function. Any help is appreciated.
1. (10 pts ) Implement a class called Question. The UML below is a starting point. You may add other instance variables and methods if your group wants additional features represented. Please see the schedule for the review date of this class.
Question
-question: string
-answer : string
+Question() //constructor. Set instance variables
+Question(query : string, result : string) //constructor. Set instance variables
+getQuestion() : string //returns the question
+getAnswer : string //returns the answer to this question
+answerCorrect(candidateAnswer :string) : boolean //returns true if the candidate answer matches the answer
+displayQuestion() : void //displays this question and its answer
2. (10 pts) Implement a class called Quiz that manages an array of up to 25 Question objects. It keeps track of the correct and incorrect responses. The UML below is a starting point. Your group may add to this design and incorporate additional features. Please see the schedule for the review data of this class.
const int MAX_QUESTIONS = 25; //the size of the array
Quiz
-questions : Question[MAX_QUESTIONS] //an array named questions that holds Question objects
-current : int //value of the index of the current location available in the questions array
-correct : int // number of correct answers
-incorrect : int //number of incorrect answers
+Quiz( ) //constructor. Instance variables current, correct, and incorrect set to 0.
+add(newQuestion : Question) : void //add the specified question to the questions array if room available
+giveQuiz( ) : void // present each question to the user, accept an answer for each one, and keep track of the results (the number of correct and incorrect answers).
+getNumCorrect() : int //returns the number of correct answers
+getNumIncorrect() : int //returns the number of incorrect answers
3. (10 pts) Define a tester/driver class called QuizShow with a main method that creates a Quiz object. Create 5 Question objects (read in a question and answer from a file) and populate the quiz using the add method. Then give the quiz and print the final results.
4. (10 pts Extra Credit possible) Add the following enhancements:
a. In Question, add a point value to questions.
b. In Quiz, tally up a final score.
c. In QuizShow, add a function manuallyFillQuiz that populates the quiz by prompting the user for a question and answer.
d. In QuizShow, add a function fillQuizFromFile that populates the quiz with questions and answers read in from a file.
e. In QuizShow, give the user the option of using manuallyFillQuiz or fillQuizFromFile.
f. In QuizShow, show the user’s final score.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#include <iostream>
const int MAX_QUESTIONS = 25; // size of the array
using namespace std;
class Quiz
{
private:
Question[MAX_QUESTIONS];
int current;
int correct;
int incorrect;
public:
Quiz();
void add(Question newQuestion);
void giveQuiz();
int getNumCorrect();
int getNumIncorrect();
};
/************************************
* Functions *
***********************************/
// displays the question and verifies the answer
//Sets all variables to zero
Quiz::Quiz()
{
int current = 0;
int correct = 0;
int incorrect = 0;
}
// displays the questions and keeps track of correct/incorrect
void Quiz::giveQuiz() : Question
{
cout << "******* Quiz ******* ";
do {
current++;
cout << "Question # " << current << endl;
cout << Question displayQuestion ;
cin >> answer; // Need to define answer. How?
if (Question answerCorrect == 1)
{
cout << "You are correct!" << endl;
correct++;
}
else
{
cout >> "You are incorrect!" << endl;
incorrect++;
}
} while (current < = 25);
}
// Adds the questions to the questions array
void Quiz::add(Question newQuestion)
{
Question
for (int i =0; i < MAX_QUESTIONS; i++)
{
}
}
// returns the number of correct answers
int Quis::getNumCorrect()
{
return correct;
}
// returns the number of incorrect answers
int getNumIncorrect()
{
return incorrect;
}
|