I am writing a small “quiz program”. It looks something like 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)
{
};
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"; };
};
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++ )
{
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 (or should) I call class methods of class cQuestion? I was thinking about using an array of pointers for these members (cQuestion :: question1, cQuestion :: question2, etc.), or overloading the index operator [].
I'm not sure if this is good or bad anyway. Should I consider a different solution or somehow use both together? Or am I completely missing the point?
source
share