Question
Two-dimensional arrays are used to represent a matrix, or two-dimensional grid of information. For example, a checkerboard, tic-tac-toe board, a system of streets and avenues,
Two-dimensional arrays are used to represent a matrix, or two-dimensional grid of information. For example, a checkerboard, tic-tac-toe board, a system of streets and avenues, and the seats in a theater can be represented in a two-dimensional grid. We create a 2-D array as follows:
//Create the 2D Array
//string world[row][col] = { }; string world[3][3] = { }; for (int r = 0; r < row; r++) { for (int c = 0; c < col; c++) { world[r][c] = r * c"; } }
To add data to a 2D Array you use either of the following two formats:
int x[3][4] = {0, 1 ,2 ,3 ,4 , 5 , 6 , 7 , 8 , 9 , 10 , 11}; or
int x[3][4] = {{0,1,2,3}, {4,5,6,7}, {8,9,10,11}};
The Penny Pitch game is popular in amusement parks. Pennies are tossed onto a board that has certain areas marked with different prizes. For Example:
PUZZLE | POSTER | DOLL | ||
POSTER | DOLL | BALL | ||
PUZZLE | GAME | |||
PUZZLE | BALL | POSTER | GAME | |
DOLL | GAME | BALL |
The prizes available on this board are puzzle, game, ball, poster, and doll. At the end of the game, if all of the squares that say BALL in them are covered by a penny, the player gets a ball. This is also true for the other prizes. The board is made up of 25 squares (5 x 5). Each prize appears on 3 randomly chosen squares so that 15 squares contain prizes.
Write a penny pitch game program that simulates ten pennies being randomly pitched onto the board. At the end of the game display a list of the prizes won or NONE. Name the program: PennyPitch.
Your game will have two functions.
When passing in an Array to a function you only need to pass in the ARGUMENT of the name of the Array - but when taking in the PARAMETER of the Array you need to define the Data Type and size of the Array. functionName(string arr[5][5], Int something)
1. to populate the game board with prizes. You should create the 5 x 5 2-D Array in the main and create a 1-D Array with a list of prizes to pass to the function. From here you will randomly place each prize three times. Be careful not to overwrite a prize already on the board.
You should print your 2D Array to ensure the prizes are randomly placed on the board. To print the 2D Array we will use the following code:
for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { cout << arrBoard[i][j] << "\t"; } cout << " "; }
2. play the game with the newly created board using 10 pennies. Create a variable for the pennies and set it to 10. Pass in this variable along with the 2D Array. If ALL THREE of the same prize (not the same location) is selected with the random penny thrower then the player wins that prize. Return the winner prize to the main or NONE if they do not win a prize.
print the board and prize won
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started