54.5k views
3 votes
Building the Trivia Game You will be writing a program that implements a trivia game. The program will need two classes: the Question class and the TriviaGame class. Question class The Question class represents one question and the possible answers for that question. The Question class contains the question text and the 4 possible answers. It also contains the answer number of the correct answer. The answer number is an unsigned int in the range of 1 to 4. You need to design the Question class. What behaviors does it need

1 Answer

7 votes

Answer:

/Question.h

#include<iostream>

#include<string>

using namespace std;

class Question

{

private:

string question;

string answer[4];

unsigned int correctAnswer;

public:

Question(string ques,string *ans,unsigned int x)

{

int i;

question.assign(ques);

for(i=0;i<4;i++)

{

answer[i]=ans[i];

}

correctAnswer=x;

}

~Question()

{

}

string getQuestion()

{

return question;

}

unsigned int getCorrectAnswer()

{

return correctAnswer;

}

string getAnswer1()

{

return answer[0];

}string getAnswer2()

{

return answer[1];

}

string getAnswer3()

{

return answer[2];

}string getAnswer4()

{

return answer[3];

}

int getNoOfPossibleAnswers()

{

return 4;

}

};

Step-by-step explanation:

The Question class represents one question and the possible answers for that question.

The Question class contains the question text and the 4 possible answers. It also contains the answer number of the correct answer.

The answer number is an unsigned int in the range of 1 to 4.Your Question class needs to have one or more constructors and one destructor.

It needs a member function that returns the question text. It also needs member functions that return the answer text for a specific answer

(1 through 4). The class also needs a member function that returns the number of possible answers for this question. While this is 4 today,

it could change in future versions of the class. Finally there needs to be a member function that returns the answer number of the correct answer

(a value of 1 through 4).Do not make the data members public. You can have public and private member functions as needed.

User Tuffkid
by
6.1k points