Question
***NEEDS TO BE IN C++ FORMAT!*** 1) Objective The purpose of this assignment is to make sure: You understand and can work with pointers and
***NEEDS TO BE IN C++ FORMAT!***
1) Objective
The purpose of this assignment is to make sure:
You understand and can work with pointers and dynamic memory allocation in C++.
You are comfortable with writing functions in C++, including various methods of passing
parameters.
You are familiar with repetitive structures (loops) and selection statements (if/else or switch)
in any combination and can use them in functions and to manipulate array/string data.
You can approach a complex problem, break it down into various parts, and put together a
solution.
For this assignment, please make sure you conform to Output requirements. You should now be
familiar enough with cout statements and output formatting that you should be able to EXACTLY
match the sample output (other than certain exceptions you will be informed about beforehand).
2) The Walking Red
A long time ago, in the planet of Zamenim, which is pretty far far away, a bunch of Star Trek
Redshirts beam down to explore the strange new world. They encounter several strange life forms
that have freaky mutations which make them look as if they just escaped from the nearest ToysRUs,
such as fear inducing aquatic creatures with multiple tentacles(which they immediately repressed
from memory) and giant hairy spiders that would shoot string cheese webs. During this bizarre
trek, they come across a strange warrior in white plate armor. The warrior, who is still somewhat
far, warns them that Imperial Stormtroopers are extremely precise shots and asks them to stay
away from the shield generator, shooting some warning shots to let them know that he means
business. The Redshirts are well aware of their expendable status, but since the warning shots
didnt even come close, they decide to approach anyway.
They spread out to form a line and cautiously approach the Stormtrooper, who responds by opening
fire. This turns out to be quite the battle. You are a journalist in the area, and you decide to take
upon yourself the monumental task of documenting the result of this skirmish. You mentally divide
the space between the groups into a square grid. The number of squares on one side is equal to
the initial number of Redshirts. The Redshirts advance one square for every shot the Stormtrooper
takes. The Stormtrooper usually misses, but if there happens to be a Redshirt in any of the 8 squares
surrounding the square where the shot lands, the Redshirt dies anyway. Of course, the Redshirt
dies if there is a direct hit too. You also notice that the Stormtrooper counts the initial number of Redshirts and takes an equal number of shots. The Stormtrooper wins if, after the smoke clears, all
the Redshirts are dead. If even one Redshirt manages to reach the Stormtrooper, the Redshirts win.
Your first input is the initial number of Redshirtse, followed by a list of coordinates (1 1 refers
to the first location), where the Stormtroopers shots land. The first coordinate refers to the row,
while the second refers to the column. The redshirts always start out at co-ordinate (1,y), where y
refers to the column number. Your conclusion should list who wins. If the Stormtrooper wins, all
you need to print is Stormtrooper wins. If the redshirts win, you need to print Redshirts win.,
followed by the last square where each of the Redshirts still alive are standing
Specifications Write a function called createField that takes an integer N' as the parameter and returns a pointer to a 2 dimensional dynamic array of integers. In the function, create a 2 dimensional dynamic array of integers with 'N rows and 'N columns and set all the elements to 0. Return this array. (20 points) Write a function called playGame that takes a pointer to a 2 dimensional dymanic array and the row size as parameters. Please note that the array will always contain as many rows as coulmns, so we only need one size parameter. (5 points) . In the playGame function, accept the coo-ordinates of the shots from the user, one at a time. (10 points) e Still in the playGame function, determine if the shot hit any Redshirts. If it did, then remove those Redshirts from the array by changing their values to 0. then, advance the Redshirts still in play to the next row. (30 points . At the end of the game, still in playGame, determine who won and print the appropriate answer. (20 points) . In the main function, get the number of Redshirts from the user. Call the createField function to set up the array and then call the playGame function to play the game. (10 points) . Please comment your code appropriately. (5 points) Sample Run 1 Enter the number of Redshirts: 4 Enter the coordinates of the 4 shots 1 2 3 1 2 4 4 3 Stormtrooper wins Sample Run 2 Enter the number of Redshirts: 6 Enter the coordinates of the 6 shots: 5 6 4 3 3 2 6 1 3 4 5 2 Redshirts in. Ones at (6,4), (6,5) and (6,6) are still standing Specifications Write a function called createField that takes an integer N' as the parameter and returns a pointer to a 2 dimensional dynamic array of integers. In the function, create a 2 dimensional dynamic array of integers with 'N rows and 'N columns and set all the elements to 0. Return this array. (20 points) Write a function called playGame that takes a pointer to a 2 dimensional dymanic array and the row size as parameters. Please note that the array will always contain as many rows as coulmns, so we only need one size parameter. (5 points) . In the playGame function, accept the coo-ordinates of the shots from the user, one at a time. (10 points) e Still in the playGame function, determine if the shot hit any Redshirts. If it did, then remove those Redshirts from the array by changing their values to 0. then, advance the Redshirts still in play to the next row. (30 points . At the end of the game, still in playGame, determine who won and print the appropriate answer. (20 points) . In the main function, get the number of Redshirts from the user. Call the createField function to set up the array and then call the playGame function to play the game. (10 points) . Please comment your code appropriately. (5 points) Sample Run 1 Enter the number of Redshirts: 4 Enter the coordinates of the 4 shots 1 2 3 1 2 4 4 3 Stormtrooper wins Sample Run 2 Enter the number of Redshirts: 6 Enter the coordinates of the 6 shots: 5 6 4 3 3 2 6 1 3 4 5 2 Redshirts in. Ones at (6,4), (6,5) and (6,6) are still standingStep 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