The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
C++
Trivia Game –
In this programming exercise you will create a simple trivia game for two players. The program will work like this:
Starting out with player 1, each player gets a turn at answering 5 trivia questions. (There should be a total of 10 questions.) When a question is displayed, 4 possible answers are also displayed. Only one of the answers is correct, and if the player selects the correct answer, he or she earns a point.
After answers have been selected for all questions, the program displays the number of points earned by each player and declares the player with the highest number of points is the winner.
To create this program, write a Question class to hold the data for a trivia question. The Question class should have attributes for the following data:
A trivia question
Possible answer 1
Possible answer 2
Possible answer 3
Possible answer 4
The number of the correct answer (1, 2, 3, or 4)
The Question class also should have an appropriate constructor, accessors, and mutators. The Header file has been included for you to implement.
The program should have an array containing 10 Question objects, one for each trivia question. Make up your own trivia questions on the subject or subjects of your choice for the objects and read Trivia Questions with possible answers and number of the correct answer from an input text file that you create (trivia.txt) in any format.
I have the Question class written:
#ifndef QUESTION_H
#define QUESTION_H
using namespace std;
#include
class Question
{
private:
string triviaQuestion;
string answerOne;
string answerTwo;
string answerThree;
string answerFour;
int correctAnswer;
public:
Question();
Question(string question, string one, string two, string three,
string four, int answer);
void setTriviaQuestion(string question);
void setAnswerOne(string one);
void setAnswerTwo(string two);
void setAnswerThree(string three);
void setAnswerFour(string four);
void setCorrectAnswer(int answer);
string getTriviaQuestion();
string getAnswerOne();
string getAnswerTwo();
string getAnswerThree();
string getAnswerFour();
int getCorrectAnswer();
bool checkGivenAnswer(int chosenNumber);
};
#endif
I need help with the Main class. Here is the sample output:
Player 1:
What is 1 + 1?
1: 1
2: 2
3: 3
4: 4
Choose an answer by entering a number from 1 to 4.
2
Player 1:
What is 2 + 2?
1: 1
2: 2
3: 3
4: 4
Choose an answer by entering a number from 1 to 4.
1
Player 1:
What is 3 + 3?
1: 2
2: 4
3: 6
4: 8
Choose an answer by entering a number from 1 to 4.
1
Player 1:
What is 4 + 4?
1: 2
2: 4
3: 6
4: 8
Choose an answer by entering a number from 1 to 4.
3
Player 1:
What is 5 + 5?
1: 7
2: 8
3: 9
4: 10
Choose an answer by entering a number from 1 to 4.
2
Player 2:
What is 6 + 6?
1: 12
2: 14
3: 16
4: 18
Choose an answer by entering a number from 1 to 4.
1
Player 2:
What is 7 + 7?
1: 12
2: 14
3: 16
4: 18
Choose an answer by entering a number from 1 to 4.
2
Player 2:
What is 8 + 8?
1: 12
2: 14
3: 16
4: 18
Choose an answer by entering a number from 1 to 4.
3
Player 2:
What is 9 + 9?
1: 12
2: 14
3: 16
4: 18
Choose an answer by entering a number from 1 to 4.
1
Player 2:
What is 10 + 10?
1: 16
2: 18
3: 20
4: 22
Choose an answer by entering a number from 1 to 4.
4
Player 1 scored 1 points
Player 2 scored 3 points
The winner is Player 2
Press any key to continue . .Â