Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is the template file: #include #include using namesapce std; //Global const

ID: 3626405 • Letter: T

Question

This is the template file:

 

#include

 

#include

 

using namesapce std;

 

//Global constant

 

const int NUM_HEAP = 3;                           //Number of heaps

 

//FUNCTION PROTOTYPES GO HERE:

 

 

int main()

 

{

 

int heap[NUM_HEAPS];

 

int player(1);

 

//Read number of elements in each heap

 

 

 

//Draw heaps as row of *'s

 

 

 

//WHILE some heap is not empty DO

 

 

 

//Read heap to modify and number of elements to remove from heap

 

 

 

//Remove elements from heap

 

 

 

//IF all the heaps are empty, THEN

 

 

 

//Player has won.

 

//Print win message.

 

 

 

//ELSE

 

 

 

//Player continus

 

//Redraw heaps

 

 

 

//Change to other player

 

 

 

//END IF

 

//END WHILE

 

}

 

 

 

// FUNCTION DEFINITIONS GO HERE:

 

 

 



Here is the instruction:

 (1) Prompt and read number of elements in each heap;
(2) Draw the heaps;
(3) while (some heap is NOT empty) do
(4) Prompt and read the next player move. (Prompt and read the heap to modify and the number of elements to remove from the heap.);
(5) Remove the specified number of elements from the specified heap;
(6) if (all heaps are empty) then
(7) Print a message congratulating the winning player.
(8) Else
(9) Redraw the heaps;
(10) Change to the other player;
(11) end
(12) end

1. All functions should be written AFTER the main procedure.
2. A function prototype should be written for each function and placed BEFORE the main procedure.
3. Each function should have a comment explaining what it does.
4. Each function parameter should have a comment explaining the parameter.
5. As in nim3_template.cpp, your program should have a global constant definition: const int NUM_HEAPS = 3;
Your program SHOULD NOT use any other global variables.
6. As in nim3_template.cpp, the number of elements in the heaps should be stored in an array: int heap[NUM_HEAPS];
7. As in nim3_template.cpp, the current player (1 or 2) should be stored in an integer: int player(1);
8. The function descriptions below do not specify the exact parameters for the functions, nor whether they are passed by value or by reference nor whether array parameters should be const. You will need to decide this for yourself.
Scalar (single value) parameters which are modified by the function need to be passed by reference. All others should be passed by value.
Array parameters for arrays which are modified should NOT be const. All other array parameters should be const.
9. Write a function which prompts and reads in the number of elements in each heap. Call this function to implement step 1 of the algorithm. For each heap, the function should check that the number entered is positive. If it is not positive, the program should print an error message and prompt and read again the number of elements until it receives a positive number.
The main program should call a single function f() to read in all three heaps. (Choose a better function name than f().) However, to avoid duplication of code, write a function to read a single heap and call it three times from function f(), once for each heap, The function modifies the values in the array heap[].
10. Write a function to draw a representation of the heaps. Call this function to implement steps 2 and 9 of the algorithm. Each heap is represented on a separate row. In the row for heap i, there is a label “Heap i: ” followed by n *'s, where n is the number of elements in heap i. For instance if heap 0 has 3 elements heap 1 has zero elements and heap 2 has 8 elements, the function draw_heaps() should output:
Heap 0: ***
Heap 1:
Heap 2: ********
The function to draw the heaps should output an empty line before and after the first and last row, respectively.
The main program should call a single function g() to draw all three heaps. (Choose a better function name than g().) However, to avoid duplication of code, write a function to draw a single row corresponding to a single heap and call it three times from function g(), once for each heap.
11. Write a function which returns true if all the heaps have zero elements and returns false otherwise. Call this function to implement steps 3 and 6 of the algorithm. Note that the same function can be used both for step 3 and step 6.
12. Write a function which prompts and reads a player’s next move. Call this function to implement step 4 of the algorithm.
The function first prompts for the heap from which to remove elements.
If the heap number is not 0, 1 or 2, print an error message that the heap number is illegal.
If the heap has no elements, print an error message that the heap has no elements.
Continue prompting and reading until the player enters a valid heap number which represents a heap with one or more elements.
The function next prompts for the number of elements to remove from the specified heap.
If the number is not positive, print an error message that the number must be positive.
If the number is greater than the number of elements in the specified heap, print an error message that there are only x elements in the heap.
Continue prompting and reading until the player enters a valid number of elements which is less than or equal to the number of elements in the heap.
13. Write a function which removes the specified number of elements from the specified heap. Call this function to implement step 5 of the algorithm.
The function modifies the values in array heap[].
14. Write a function to print a message congratulating the winning player. The message should identify who won (player 1 or player 2.) Call this function to implement step 7 of the algorithm.
15. Write a function to change the current player. Call this function to implement step 10 of the algorithm. If the value of variable player is 1, then the function should change the value of player to 2. If the value of variable player is 2, then the function should change the value of player to 1.
The function modifies the value of player.

 

 

 

 



 

 

 

 

Explanation / Answer

include #include using namespace std; int main () { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote