Question: I need to write a program in C++ that is a trivia game. Here is the description. For this project you will need two classes:

I need to write a program in C++ that is a trivia game. Here is the description.

For this project you will need two classes: Player and Question.

Declare and define each in their own .h and .cpp files.

In your Source.cpp file, create a trivia game for multiple players. Create 10 Question objects (You can come up with your own trivia questions). Each question should have 4 possible answers, with only one being correct. At the beginning of the game, ask the user how many players are playing. Create as many Player objects as are requested.

Then, ask each player 5 of the 10 questions. i.e. ask player 1 the first question, then ask player 2 the first question, etc.

Do not tell the players which questions they got right or wrong until the end of the game.

Inside each Player object, create two vectors that contain pointers to Question objects. One vector contains pointers to the questions the player got right and one contains pointers to the questions the player got wrong.

At the end of the game, print out which players got each question right. Allow the user to play again, asking 5 different questions this time. Re-use the same Player objects, but make sure to clear the necessary data.

Here is my beginning work which I can't get to compile. Where am I going wrong?

Player.h

#ifndef PLAYER_H

#define PLAYER_H

class Player{

private:

int playerNum;

int score;

public:

//Player();

//~Player();

void setNumber(int);

void incScore(int);

int getScore();

//int getNum();

};

#endif

Player.cpp

#include "Player.h"

void Player::setNumber(int n) {

playerNum = n;

}

void Player::incScore(int n) {

score = score + n;

}

int Player::getScore() {

return score;

}

Question.h

#ifndef QUESTION_H

#define QUESTION_H

#include

class Question

{

private:

string question;

Answer A;

Answer B;

Answer C;

Answer D;

public:

void setQuestion(string);

void setA(string, bool);

void setB(string, bool);

void setC(string, bool);

void setD(string, bool);

string getQuestion();

void printQuestion();

};

struct Answer {

string answer;

bool isCorrect;

};

#endif

Question.cpp

#include "Question.h"

#include

using namespace std;

void Question::setQuestion(string s) {

question = s;

}

void Question::setA(string s, bool a) {

A = { s,a };

}

void Question::setB(string s, bool a) {

B = { s,a };

}

void Question::setC(string s, bool a) {

C = { s,a };

}

void Question::setD(string s, bool a) {

D = { s,a };

}

string Question::getQuestion() {

return question;

}

void Question::printQuestion() {

cout << question << endl << A.answer << endl << B.answer;

cout << endl << C.answer << endl << D.answer << endl;

}

Main.h

class main

{

public:

main();

~main();

};

Main.cpp

#include "main.h"

//#include "Player.h"

#include "Question.h"

//#include

//#include

//#include "Question.cpp"

using namespace std;

int main() {

Question one;

one.setQuestion("What's 2 + 2?");

one.printQuestion();

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!