Hi there.
I am writing a small "quiz program". It looks similar to this:
#include <cstdlib>
#include <iostream>
#include <time.h>
using namespace std;
using std::cout;
class cQuestion
{
private:
static short goodAnswers[20][2];
public:
static void checkAnswer(int questNumber)
{
/* checking input, checking if answer is bad or good */
/* putting the answer to cQuiz::answArr */
};
static void question1(void) { cout << "this is question 1"; };
static void question2(void) { cout << "this is question 2"; };
static void question3(void) { cout << "this is question 3"; };
static void question4(void) { cout << "this is question 4"; };
static void question5(void) { cout << "this is question 5"; };
/*and so on to question 20*/
};
short cQuestion::goodAnswers[20][2] = {0,0};
class cQuiz
{
private:
static short questArr[5];
static short answArr[5];
public:
void drawRandom(void)
{
srand ( time(NULL) );
for (int i = 0; i < 5; i++ )
questArr[i] = rand() % 20 + 1;
};
void askQuestions(void)
{
for (int i = 0; i < 5; i++ )
{
/* call questions by question number from questArr */
/* HOW SHOULD I CALL CERTAIN cQuestion CLASS MEMBER ?? */
cQuestion::checkAnswer(questArr[i]);
}
};
};
short cQuiz::questArr[5] = {0};
short cQuiz::answArr[5] = {0};
int main(int argc, char *argv[])
{
cQuiz quiz;
quiz.drawRandom();
quiz.askQuestions();
system("PAUSE");
return EXIT_SUCCESS;
}
I am wondering, how can (or should) I call class cQuestion member methods ? I was thinking about using an array of pointers to these members (cQuestion::question1, cQuestion::question2, and so on) or overloading subscript operator[].
I am not sure if either way is good or bad. Should i consider different solution or somehow use both together? Or am I completely missing the point?