player gets a turn at answering five trivia questions. There are a total of 10 questions. When a question is displayed, four possible answers are also displayed. Only one of the answers is correct, and if the player selects the correct answer, they earn a point. After the answers have been selected for all of the questions, the program displays the number of points earned by each player and declare the player with the highest number of points to be the winner. The players will have the option of playing another round.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

CIS 2275 C++ Programming Part I

Program 6 Trivia Game

 

In this program, create a simple trivia game for two players. It will work like this:

Starting with player 1, each player gets a turn at answering five trivia questions. There are a total of 10 questions. When a question is displayed, four possible answers are also displayed. Only one of the answers is correct, and if the player selects the correct answer, they earn a point.

After the answers have been selected for all of the questions, the program displays the number of points earned by each player and declare the player with the highest number of points to be the winner.

The players will have the option of playing another round.

 

The flow of the program will be:

Show the Header information.

Create an array of Question structs.

Read the questions from the text file.

If the questions were properly read, start a do-while loop.

Declare and initialize:

playerOnePoints and playerTwoPoints

questionNumber

start a while loop - while questionNumber is less than 10

Identify player One is being asked the question with a cout

call the function PlayARound(the Question struct variable, the questionNumber, the playerOnePoints)

Identify player Two is being asked the question with a cout.

call the function PlayARound(the Question struct variable, the questionNumber, playerTwoPoints)

When the control exits out of the while loop, call ShowFinalScores(playerOnePoints, playerTwoPoints);

Ask the player if they want to play again. If yes, loop up to the top of the do-while loop. If no, drop out and say good-bye.

return 0;

 

 

Functions.h file contains:

Constants for filename, number of questions (10), and number of answers (4)

 

The Question struct declaration:

struct Question

{

string question;

string answers[NUM_ANSWERS];

int correctIndex; //the correct index for the answer

};

Function Prototypes:

bool InitQuestions(Question questions[]);

void DisplayQuestion(Question questions[], int index);

bool CheckAnswer(Question questions[], int questionNum, int playerAnswer);

void PlayARound(Question quest[], int &questionNum, int &playerPoints);

void ShowFinalScores(int playerOnePoints, int playerTwoPoints);

 

 

InitQuestions will;

Read a text file which contains the questions and answers and the correct index. The filename may be contained in the constant in the .h file.

When the file is opened, test to make sure it is valid. If not, return false.

If true, read the text into the appropriate locations in the struct array element.

return true.

PlayARound will:

Call DisplayQuestion.

Ask the user to enter the answer number.

Read in the user answer, make sure the answer is in range. If the user answer is not in range let them know that their answer is not in range and ask until their answer is in range.

Call CheckAnswer and assign the return into a bool.

Check the bool and if it is true, increment the player’s points.

Increment the questionNumber by 1.

DisplayQuestion will:

cout the question string.

cout a heading that states answers.

cout the 4 answer strings.

CheckAnswer will:

check if the index selected by the plays matches the index that is correct.

cout a message of success or failure and if the player is incorrect, give the correct answer.

Return true if the player was correct and false otherwise.

ShowFinalScores will, using nice formatting:

cout the points for each player and announces who won or if they tied.

cout the number of games won by each player

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 6 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education