Question: PROGRAM DESCRIPTION In this project, you have to write a C++ program to design a game that involves guessing a number between two randomly generated

PROGRAM DESCRIPTION In this project, you have to write a C++ program to design a game that involves guessing a number between two randomly generated numbers. This game is similar to the one you wrote in Project 1, hence you can reuse your code from Project 1. Just like in Project 1, you cannot see the randomly generated numbers at start. If you guess correctly, you earn points. If you guess incorrectly, you lose points. You can keep on guessing as long as you have points remaining. You can also choose to display one of the two numbers (either the lower bound or the upper bound) to make the game easier. If you choose to display a number to get help, you earn less points for correct guesses and lose more points for incorrect guesses. You CANNOT, of course, display both bounds. In this game, there are two 2D arrays (matrices) - one is displayed (i.e. visible to the player) and the other one is hidden (i.e. not visible to the player). The objective of the game is to eliminate all the numbers in the hidden array and display which numbers have been eliminated via the visible array. Note you SHOULD NOT display the hidden array, since it has all the answers. PROGRAM REQUIREMENTS 1. As with all projects in this course, your program's output will display your name, your EUID, your e-mail address, the department name, and course number. This means that your program will print this information to the terminal. 2. Declare a global enumeration constant with values displayLeft, displayRight, Guess, Reset and Exit (in order) and assign integer values 1 to 5 to them respectively. These five items will correspond to the menu choice you will provide the player. 3. Write a function named getName with return type of string. Inside this function: Using a suitable message, ask the player for the name of the player. The name may have multiple words. Only alphabets (A-Z or a-z) and whitespaces are permitted in the account name. o If the player enters any other characters in the name, you need to generate an error message and ask for the name again. o Your program must keep on asking the player to enter the name until the player enters it correctly. The player may type the name in either uppercase or lowercase, but you need to convert every initial to uppercase and every other alphabet to lowercase. This function needs to return the name of the player and will be called from the main function. 4. Write a function named genShowMatrix. This function will initialize the visible array. Inside this function: Set all the elements of the corresponding matrix to -1.

This function will be called when relevant to initialize the visible array. 5. Write a function named genHideMatrix. This function will initialize the hidden array. Inside this function: In this function, set all elements of the hidden array to randomly generated numbers between the lower and the upper bounds, inclusive. Since you are randomly generating the numbers, the numbers may repeat in the array. This function will be called when relevant to initialize the hidden array. 6. Write a function named showMatrix to display the corresponding 2D array. You will call this function to display the 2D array, when relevant. 7. Write a function named setdisplayLeft. Inside this function: If the player chooses to display the integer on the left (the lower bound), display the first/smaller randomly generated integer instead of -1. o Provide a message saying a correct guess will only earn 1 point and an incorrect guess will lose 10 points in the game. o Make sure the player does not display both bounds simultaneously. 8. Write a function named setdisplayRight. Inside this function: If the player chooses to display the integer on the right (the upper bound), display the second/larger randomly generated integer instead of -1. o Provide a message saying a correct guess will only earn 1 point and an incorrect guess will lose 10 points in the game. o Make sure the player does not display both bounds simultaneously. 9. Write a function named eliminate. In this function: This function will be called from the guess function (see later). This function will obtain two integer values representing the row index and the column index from the guess function. This function will set all values in the corresponding row and column to zero in both visible and hidden arrays. For example, if the received parameters are row index=1, column index=3, this function will set all values in second row equal to zero and all values in the fourth column equal to zero. 10. Write a function named allZeros of Boolean return type. In this function: You will check if all elements in a 2D array is zero. If so, you will return true, otherwise return false. 11. Write a function named guess. Inside this function: Using a suitable message, ask the user to guess the values in the hidden array. Note that the bounds are hidden initially, so the player doesn't know what numbers are used to create the matrix. Of course, the player can choose to reveal one of the two bounds at a cost.

Check if the guess matches any value of the hidden array. If there is a match, call the function eliminate, and pass the corresponding row and column indices where the match occurred. o Increment points of the player accordingly. Provide suitable message. If there is no match, decrement points of the player accordingly. Provide suitable message. If the player has displayed either of the two bounds, you need to increment by 1 point and decrement by 10 points, when appropriate. If the player has NOT displayed any of the two bounds, you need to increment by 5 points and decrement by 5 points, when appropriate. Update the player with the points balance after every guess. This function will be called from the main function. 12. Write function named initialize. This function will be called to set the starting parameters of the game as well as to restart the game. Inside this function, you will: Generate lower and upper bounds. o Generate two seeded random integers: one in the range of 100 to 199 inclusive, representing a lower bound, and the other in the range of 200 to 299 inclusive, representing an upper bound. Set the displayed lower and upper bounds to -1. Call the function genHideMatrix to generate the hidden array. You will need to pass the randomly generated lower and upper bounds as well. Call the function genShowMatrix to generate the displayed array. Inside your main function: 13. Declare an integer variable and initialize it to 100. This variable represents the number of points each player starts the game with. 14. Declare two integers to represent the lower and the upper bounds being displayed. Since you cannot display the actual lower and upper bounds being randomly generated, you will only display these integers. In case, the player wants to see the randomly generated integer, you will replace one of the -1 with the actual random number being generated. 15. Call the function initialize to set the starting game parameters. 16. Call the function getName to get the name of the player and display a welcome message using the name. 17. Based on the enumerated constant data, generate menu choice for the player. Using an integer variable, ask the player to select from the menu. 18. Design a switch-case block with a default case, using the enumerated data constants your cases. Based on the player input of Step 17, one of the cases will execute. You must use a variable of your enumeration constant type as the switching expression. If the player chooses to display the integer on the left (the lower bound), call the function setdisplayLeft. If the player chooses to display the integer on the left (the lower bound), call the function setdisplayRight. If the player chooses to guess a number between the two bounds, call the function guess.

o After returning from the function guess, check if all the values in the hidden array have been eliminated by calling the allZeros function. If yes, the use has won the game. Ask the user if the user wants to play another game. If the user chooses to play another game, start a new game by calling the function initialize. If the player chooses to reset the game, restart a new game by calling the function initialize. Deduct 1 point for this choice and provide the player updated points balance. If the player chooses to Exit, display a suitable goodbye message using the name of the player and display the final points balance. If the player enters a wrong choice, use the default case to provide an error message and ask the player to enter again. 19. You must use a suitable loop of choice to allow the player to repeat Steps 17 and 18 i.e. choosing from the menu and executing the corresponding case, until the use chooses to Exit or the points balance falls below zero (becomes negative). 20. Your program must have the following functions: getName setdisplayLeft setdisplayRight guess eliminate allZeros showMatrix genHideMatrix genShowMatrix initialize main If you are missing any of these functions, points allocated to these functions will not be given. You may use additional functions in your code, but you will not get points for writing them. 21. Your program source code should be named "euidProject2.cpp", without the quotes. where euid should be replaced by the EUID of the submitting student. If you are working in a group, you must enter their names and EUIDs as comments in the code file. Only one submission per group is needed. 22. Your program will be graded based largely on whether it works correctly on the CSE machines (e.g., cell01, cell02, ..., cell06), so you should make sure that your program compiles and runs on a CSE machine. DESIGN (ALGORITHM): On a piece of paper (or word processor), write down the algorithm, or sequence of steps, that you will use to solve the problem. You may think of this as a "recipe" for someone else to follow. Continue to refine your "recipe" until it is clear and deterministically solves the problem. Be sure to include the steps for prompting for input, performing calculations, and displaying output. You should attempt to solve the problem by hand first (using a calculator as needed) to work out what the answer should be for a few sets of inputs. Type these steps and calculations into a document (i.e., Word, text, or PDF) that will be submitted along with your source code. Note that if you do any work by hand, images (such as pictures) may be used, but

they must be clear and easily readable. This document shall contain both the algorithm and any supporting hand-calculations you used in verifying your results. TESTING: Test your program to check that it operates as desired with a variety of inputs. Then, compare the answers your code gives with the ones you get from hand calculations.

write a c++ program

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 Programming Questions!