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

Create an MS Word document which contains the code trace of program 19-10, Tower

ID: 3775954 • Letter: C

Question

Create an MS Word document which contains the code trace of program 19-10, Tower of Hanoi
with 4 discs, by changing line 11 to the following:
const int NUM_DISCS = 4;
Your document must have two columns labeled line number and code trace narrative. For each line
number traced/executed, you are to place the line number in a new row’s first column and complete
the corresponding narrative in the second column. You are expected to use full sentences in the
narrative portion. You may begin your code trace at line 11 and ends at line 20 (the int main
function).
#include <iostream>
using namespace std;

// Function prototype
void moveDiscs(int, int, int, int);
int main()
{
const int NUM_DISCS = 3; // Number of discs to move
const int FROM_PEG = 1; // Initial "from" peg
const int TO_PEG = 3; // Initial "to" peg
const int TEMP_PEG = 2; // Initial "temp" peg

// Play the game.
moveDiscs(NUM_DISCS, FROM_PEG, TO_PEG, TEMP_PEG);
cout << "All the pegs are moved! ";
return 0;
}

void moveDiscs(int num, int fromPeg, int toPeg, int tempPeg)

{

if (num > 0)

{

moveDiscs(num 1, fromPeg, tempPeg, toPeg);

cout << "Move a disc from peg " << fromPeg

<< " to peg " << toPeg << endl;

moveDiscs(num 1, tempPeg, toPeg, fromPeg);

}

}

this is c++

Explanation / Answer

Move a disc from peg 1 to peg 2

Move a disc from peg 1 to peg 3

Move a disc from peg 2 to peg 3

Move a disc from peg 1 to peg 2

Move a disc from peg 3 to peg 1

Move a disc from peg 3 to peg 2

Move a disc from peg 1 to peg 2

Move a disc from peg 1 to peg 3

Move a disc from peg 2 to peg 3

Move a disc from peg 2 to peg 1

Move a disc from peg 3 to peg 1

Move a disc from peg 2 to peg 3

Move a disc from peg 1 to peg 2

Move a disc from peg 1 to peg 3

Move a disc from peg 2 to peg 3

All the pegs are moved!

Line No. Description 7 NUM_DISCS is initialized to 7. 8 FROM_PEG is initialized to 1. 9 TO_PEG is initialized to 3. 10 TEMP_PEG is initialized to 2. 12 moveDiscs(4, 1, 3, 2) is called. 18 Condition 4 > 0 is validated to true. 20 moveDiscs(3, 1, 2, 3) is called. 18 Condition 3 > 0 is validated to true. 20 moveDiscs(2, 1, 3, 2) is called. 18 Condition 2 > 0 is validated to true. 20 moveDiscs(1, 1, 2, 3) is called. 18 Condition 1 > 0 is validated to true. 20 moveDiscs(0, 1, 3, 2) is called. 18 Condition 0 > 0 is validated to false. 21 The message is printed "Move a disc from peg 1 to peg 2" 22 moveDiscs(0, 3, 2, 1) is called. 18 Condition 0 > 0 is validated to false. 21 The message is printed "Move a disc from peg 1 to peg 3" 22 moveDiscs(1, 2, 3, 1) is called. 18 Condition 1 > 0 is validated to true. And this continues..... for 15 lines of output, and the output will be...
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