Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this C++ programming exercise you will create a simple trivia game for two pl

ID: 3827309 • Letter: I

Question

In this C++ 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.

Explanation / Answer

#include <iostream>
#include <iomanip>
#include "Question.h"
using namespace std;
void displayInfo(Question[], int)
int main()
{
Game trivia[4];
int count = 0;
int onechoice;
int twochoice;
int onepoints;
int twopoints;
int x;
cout << "This trivia game consists of random questions" <<endl;
cout << "The player with the best score at the end WINS!!!" <<endl;
trivia[0].setQuestion("Who is the fastest man in the world? ");
trivia[0].setAnswer1("1. Tyson Gay");
trivia[0].setAnswer2("2. Asafa Powell");
trivia[0].setAnswer3("3. Usian Bolt");
trivia[0].setAnswer4("4. Maurice Green");
trivia[0].setCorrect(3);
trivia[1].setQuestion("Which personality does not belong to the sport soccer? ");
trivia[1].setAnswer1("1. Christiano Ronaldo");
trivia[1].setAnswer2("Micheal Jordon");
trivia[1].setAnswer3("David Beckham");
trivia[1].setAnswer4("Peter Cargill");
trivia[1].setCorrect(2);
trivia[2].setQuestion("?");
trivia[2].setAnswer1;
trivia[2].setAnswer2;
trivia[2].setAnswer3;
trivia[2].setAnswer4;
trivia[2].setCorrect();
trivia[3].setQuestion("?");
trivia[3].setAnswer1;
trivia[3].setAnswer2;
trivia[3].setAnswer3;
trivia[3].setAnswer4;
trivia[3].setCorrect();
trivia[4].setQuestion("?");
trivia[4].setAnswer1;
trivia[4].setAnswer2;
trivia[4].setAnswer3;
trivia[4].setAnswer4;
trivia[4].setCorrect();
while(count < 4, count++) {
       cout << setw(10) << " QUESTION " << (count + 1) << endl;
       displayGame(trivia, count);
       cout << "Player 1's answer: ";
       cin >> onechoice;
       cout << "Player 2's answer: ";
       cin >> twochoice;
       if(trivia[count].getCorrect() == onechoice) {
           onePoints++;
       }
       if(trivia[count].getCorrect() == twochoice) {
           twoPoints++;
       }
       cout << endl << endl;
   }
   if ( twoPoints) {
       cout << "Both players were tied." << endl;
   }
   if ( onePoints > twoPoints) {
       cout << "PLAYER ONE IS THE WINNER!!!!!!" << endl;
   }else {
       cout << "PLAYER TWO IS THE WINNER!!!!!!" << endl;
   }
   cout << "Thanks for playing, press any key to exit.";
   cin >> x;

}