Do My Homework / Homework Help Answers / C++ Homework Help / Write a complete program that will do the steps

Write a complete program that will do the steps

Need help with this question or any other C++ assignment help task?

In this lab assignment we are practicing with pointers in the context of some made up game. The assignment is designed as a series of steps that need to be completed in the order they are outlined. So attempt them sequentially and in the order given. Step 1. Populate a 10 by 10 2d array of integers called board by some random numbers in the range 10 - 500. Step 2. Display this 2d array on the screen. Try formatting, so that this array looks neat and organized. Step 3. Declare a pointer to int called iPtr. Initialize it to nullptr. Step 4. Define a function called maxPointer that receives a 1d array and returns a pointer to the maximum element of that array. The prototype of this function is given below: int * maxPointer ( int [], int); Step 5. Set up a loop to iterate over the rows, call maxPointer on each row and use the pointer that it returns to swap the element it is pointing to with the very last element of that row. When done with all the rows, the last column will have the highest value per row. Step 6. Add a statement that makes the iPtr point to the very last element of the first row of our 2d array. Step 7. Set up a loop so that iPtr can iterate along the very last column of the board array. Think about the size of data between the elements of the very last column of this 2d array, that is the size of the jump, iPtr needs to make to get to the next element of the last column. Use this loop (and this loop ONLY) AND the iPtr (and ONLY iPtr) to find the maximum value of the last column. In order to accomplish this task we need to declare another pointer called maxPtr. This loop should leave/keep the maxPtr pointing to the maximum element of the last column, whereas the iPtr does the actual "walk" along the column. Can we say the maximum of the last column is also the maximum of the entire 2d array? Display the content of what maxPtr is pointing to after this step to verify whether it is indeed the maximum value of the 2d array. Step 8. At this point, we know that maxPtr is pointing to the array element with maximum value of the last column. Let’s try something different: we have a pointer to this element, we know the column number of it but we do not know on which row it can be found. Try and see if you can come up with ONLY ADDRESS ARITHMETIC strategy to figure out the row number for this maximum number. Step 9. Let’s do another experiment: Declare tableX to be an array of 3 pointers to integers. Set up a loop to assign the three pointers of array tableX to point to the first three rows of board. In order to show that you have implemented this part correctly, go ahead and display tableX in an organized fashion on the screen. Notice that after this assignment tableX can act as a 2d array, Right? You also need to use the number of columns to display the content of tableX. Step 10. To check and see how "coupled" or "connected" these two 2d arrays are, use a single loop and tableX to modify the first element of its rows to -1’s. Display tableX to verify the changes. Notice again that you need to use the number of columns for this display. Now display board to see whether anything changed for IT. Did it?
Additional Instructions:
COSC1137 - Fundamentals of Programming Lab II Fall 2022 Lab 5 This lab addresses the following major topics: • Pointers • Pointers and functions • 2d arrays You will find the instruction file along with any additional files on blackboard, when the lab starts. In this category of lab activity students are expected to write a complete program during the lab and submit the compiling program on blackboard before the end of the lab session. The instructor will give a brief description of the assignment and provides some help throughout the lab. Students can use the textbook, class notes or sample programs to complete the assignment. In this lab assignment we are practicing with pointers in the context of some made up game. The assignment is designed as a series of steps that need to be completed in the order they are outlined. So attempt them sequentially and in the order given. Step 1. Populate a 10 by 10 2d array of integers called board by some random numbers in the range 10 - 500. Step 2. Display this 2d array on the screen. Try formatting, so that this array looks neat and organized. Step 3. Declare a pointer to int called iPtr. Initialize it to nullptr. Step 4. Define a function called maxPointer that receives a 1d array and returns a pointer to the maximum element of that array. The prototype of this function is given below: int * maxPointer ( int [], int); Step 5. Set up a loop to iterate over the rows, call maxPointer on each row and use the pointer that it returns to swap the element it is pointing to with the very last element of that row. When done with all the rows, the last column will have the highest value per row. Step 6. Add a statement that makes the iPtr point to the very last element of the first row of our 2d array. Step 7. Set up a loop so that iPtr can iterate along the very last column of the board array. Think about the size of data between the elements of the very last column of this 2d array, that is the size of the jump, iPtr needs to make to get to the next element of the last column. Use this loop (and this loop ONLY) AND the iPtr (and ONLY iPtr) to find the maximum value of the last column. In order to accomplish this task we need to declare another pointer called maxPtr. This loop should leave/keep the maxPtr pointing to the maximum element of the last column, whereas the iPtr does the actual "walk" along the column. Can we say the maximum of the last column is also the maximum of the entire 2d array? Display the content of what maxPtr is pointing to after this step to verify whether it is indeed the maximum value of the 2d array. Step 8. At this point, we know that maxPtr is pointing to the array element with maximum value of the last column. Let’s try something different: we have a pointer to this element, we know the column number of it but we do not know on which row it can be found. Try and see if you can come up with ONLY ADDRESS ARITHMETIC strategy to figure out the row number for this maximum number. Step 9. Let’s do another experiment: Declare tableX to be an array of 3 pointers to integers. Set up a loop to assign the three pointers of array tableX to point to the first three rows of board. In order to show that you have implemented this part correctly, go ahead and display tableX in an organized fashion on the screen. Notice that after this assignment tableX can act as a 2d array, Right? You also need to use the number of columns to display the content of tableX. Step 10. To check and see how "coupled" or "connected" these two 2d arrays are, use a single loop and tableX to modify the first element of its rows to -1’s. Display tableX to verify the changes. Notice again that you need to use the number of columns for this display. Now display board to see whether anything changed for IT. Did it? • Submit your program by the end of the lab session you attended in person. Only submissions by students who attended the lab in person will be considered for grading. • Make sure you submit a program that compiles. An incomplete program that compiles could possibly earn partial points, a non-compiling program will be considered void. • This is an individual work, you may ask the instructor for some help. However you should not interact with fellow students. COSC1137 - Fundamentals of Programming Lab II Fall 2022
There are no answers to this question.
Login to buy an answer or post yours. You can also vote on other others

Get Help With a similar task to - Write a complete program that will do the steps

Related Questions

Similar orders to Write a complete program that will do the steps
Popular Services
Tutlance Experts offer help in a wide range of topics. Here are some of our top services: