
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:
1. Show the Header information.
2. Create an array of Question structs.
3. Read the questions from the text file.
4. If the questions were properly read, start a do-while loop.
5. Declare and initialize:
a. playerOnePoints and playerTwoPoints
b. questionNumber
6. start a while loop - while questionNumber is less than 10
7. Identify player One is being asked the question with a cout
8. call the function PlayARound(the Question struct variable, the questionNumber, the playerOnePoints)
9. Identify player Two is being asked the question with a cout.
10. call the function PlayARound(the Question struct variable, the questionNumber, playerTwoPoints)
11. When the control exits out of the while loop, call ShowFinalScores(playerOnePoints, playerTwoPoints);
12. 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.
13. 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;
a. 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.
b. When the file is opened, test to make sure it is valid. If not, return false.
c. If true, read the text into the appropriate locations in the struct array element.
d. return true.
PlayARound will:
a. Call DisplayQuestion.
b. Ask the user to enter the answer number.
c. 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.
d. Call CheckAnswer and assign the return into a bool.
e. Check the bool and if it is true, increment the player’s points.
f. Increment the questionNumber by 1.
DisplayQuestion will:
a. cout the question string.
b. cout a heading that states answers.
c. cout the 4 answer strings.
CheckAnswer will:
a. check if the index selected by the plays matches the index that is correct.
b. cout a message of success or failure and if the player is incorrect, give the correct answer.
c. Return true if the player was correct and false otherwise.
ShowFinalScores will, using nice formatting:
a. cout the points for each player and announces who won or if they tied.
b. cout the number of games won by each player

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 9 images

- C++ with Text Artsarrow_forwardHangman gameWrite a terminal based on the game of Hangman. In a hangman game, the player is given a wordthat they need to guess, with each letter of the word represented by an underscore/blank. Theplayer tries to guess a letter of the word by entering it into the terminal. If the letter is correct, theblank corresponding to that letter is filled in. If the letter is incorrect, a part of a stick figure isdrawn. The player has a limited number of incorrect guesses before the stick figure is fully drawnand the game is lost. The player wins the game if they guess all the letters of the word before thestick figure is fully drawn.The program should have an array of possible words to choose from. A different word should berandomly chosen from the array every time we run the program.Others: Do not use GOTO statementsarrow_forwardRock, Paper, Scissors Game - MUST BE WRITTEN IN PSEUDOCODEarrow_forward
- def area(side1, side2): return side1 * side2s1 = 12s2 = 6Identify the statements that correctly call the area function. Select ALL that apply. Question options: area(s1,s2) answer = area(s1,s2) print(f'The area is {area(s1,s2)}') result = area(side1,side2)arrow_forwardJAVA:arrow_forwardComputer Science Part C: Interactive Driver Program Write an interactive driver program that creates a Course object (you can decide the name and roster/waitlist sizes). Then, use a loop to interactively allow the user to add students, drop students, or view the course. Display the result (success/failure) of each add/drop.arrow_forward
- Java Programming A bakery company provides a bonus of a new bakery product package for customers who buy at least 10 breads in the company anniversary award which will be celebrated in the next three months. To get the bonus, the customer is given the opportunity three times to guess a number determined by the application from numbers 1 to 20. For each guess number given by the customer, the application will respond as follows:• If the guessed number is smaller than the lucky number, you will see the words "Bigger Number"• If the guessed number is greater than the lucky number, you will see the words "Smaller Number"• If the guessed number is the same as a lucky number, it will match the words "Congratulations ... you found a LUCKY number"As part of the company's IT team, you serve to create a lucky number guessing game console.A. Determine the inputs and outputs of the design programb. Draw a Flowchart of the programc. Write Coding to make the applicationd. Give Screen shoot the…arrow_forwardtranlate source program in the picture into quadruples tranlate source program in the picture into quadruples tranlate source program in the picture into quadruplesarrow_forwardMonty Hall Problem – Coding Lab In this lab, you will write a code that simulates the Monty Hall Game Show. Thegame host gives the participant the choice of selecting one of three doors. Twodoors has a goat behind them and one door has a prize. The set of choices arerandomized each round. The participant needs to select the door with the prizebehind it. When the participant selects a door, the game host reveals a door with agoat behind it. The game host opens a door (different from the one selected by theparticipant) that has a goat behind it. The participant is then given the option tochange their choice. When you run your code, the code would display a message prompting the user toinput their door choice, labelled as 1, 2, and 3. Then the code will display a doornumber (different from the one the user picked) with a goat behind it and ask theuser if they would like to change their choice. The code then displays a message onwhether the user guessed the correct door. The game then…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





