classes and arrays.

I have to create a header file and immplement a class called Quiz that manages an array of up to 25 Question objects. It keeps track of the correc tand incorrect responses.


This is the header file I have for Quiz.
I keep getting an error on the add function and I don't know what to do for the give function. In my UML the teacher gave us she said she wants it to 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). She has a tester file that actually writes out all the questions, so she doesnt want us actually writing out all of the questions. I don't really understand where to go from here. I tried breaking it down and thinking about it, im stuck.

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
#include <iostream>
#include <iomanip>
#include <string>


using namespace std;

const int MAX_QUESTIONS = 25;

class Quiz
{
	private:
		Question questions[MAX_QUESTIONS];
		int current;
		int correct;
		int incorrect;

	public:
		Quiz();
		
		void add(Question newQuestion);
		void giveQuiz();

		int getNumCorrect();
		int getNumIncorrect();
};

Quiz::Quiz()
{
      current = 0;
      correct = 0;
      incorrect = 0;
}

void Quiz::add(Question newQuestion)
{
    for (int i = 0 ; i < MAX_QUESTIONS; i++)
    {
	if (questions[i] = "unknown")   //this is looking for open elements
 
	      questions[i] = newQuestion; 
 
	else

	      cout << "No available room for new question" << endl; 
    }
}

void Quiz::giveQuiz()
{
    string answer;

    cout << add;
    cin >> answer;
}

int Quiz::getNumCorrect()
{  return correct;  }

int Quiz::getNumIncorrect()
{  return incorrect; }


I also do have a tester for Quiz, that #includes "Question.h" and #includes "Quiz.h"

And i also have a header file for Question
This is my header for Question:

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
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

class Question
{
	private:
		string question;
		string answer;

	public:
		Question();
		Question(string query, string result);

		string getQuestion();
		string getAnswer();
		bool answerCorrect(string candidateAnswer);

		void displayQuestion();
};

Question::Question()
{
	question = "No question yet";
	answer = "No answer yet";
}

Question::Question(string query, string result)
{
	question = query;
	answer = result;
}

string Question::getQuestion()
{	return question;  }

string Question::getAnswer()
{	return answer;	}

bool Question::answerCorrect(string candidateAnswer)
{
	if (candidateAnswer == answer)
		return true;
	else
		return false;
}

void Question::displayQuestion()
{
	cout << question << endl;
	cout << answer << endl;
}


and this is my code for my tester(its just here right now so i can use quiz and question)
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <iomanip>
#include <string>
#include "Quiz.h"
#include "Question.h"

using namespace std;

void main()
{

}
What error are you getting? You need to help us to help you!
Topic archived. No new replies allowed.