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

Use only C++ codes please. In this project, you will design and implement a clas

ID: 654642 • Letter: U

Question

Use only C++ codes please.

In this project, you will design and implement a class called towers, which is part of a program that lets a child play a game called Towers of Hanoi. The game consists of three pegs and a collection of rings that stack on the pegs. The rings are different sizes. The initial configuration for a five-ring game, with the first tower having rings ranging in size from one inch (on the top) to five inches (on the bottom).

The rings are stacked in decreasing in decreasing order of their size, and the second and third towers are initially empty. During the game, the child may transfer rings one at a time from the top of one peg to the top of another. The object of the game is to move all the rings from the first peg to the second peg. The difficulty is that the child may not place a ring on top of one with a smaller diameter. There is the one extra peg to hold rings temporarily, but the prohibition against a larger ring on a smaller ring applies to it as well as to the other two pegs.

The towers class must keep track of the status of all three pegs. You might use an array of three pegs, where each peg is an object from the previous project. The towers functions are specified here:

towers::towers(size_t n = 64);

// Precondition: 1 <= n < 64.

// Postcondition: The towers have been initialized

// with n rings on the first peg and no rings on

// the other two pegs. The diameters of the first

// pegs rings are from one inch (on the top) to n inches (on the bottom)

size_t towers::many_rings (int peg_number) const;

// Precondition: peg_number is 1, 2 or 3.

// Postcondition: The return value is the number of rings ont the specified peg.

size_t towers::top_diameter (int peg_number) const;

// Precondition: peg_number is 1,2, or 3.

// Postcondition: If many_rings (peg_number) > 0, then the return value is the

// diameter of the top ring on the specified peg; otherwise the return value is zero.

void tower::move (int start_peg; int end_peg);

// Precondition: start_peg is a peg number (1, 2, or 3), and

// many_rings(start_peg) > 0; end_peg is a different peg number

// (not equal to start_peg), and top_diameter(end_peg).

// Postcondition: The top ring has been moved from

// start_peg to end_peg.

Also overloaded the output operator so that a towers object may be displayed easily.

Use the towers object in a program that allows a child to play Towers of Hanoi. Make sure that you dont allow the child to make any illegal moves.

Explanation / Answer

using namespace std;

class towers
{
    public:
        towers(size_t);
        size_t many_rings(int) const;
        size_t top_diameter(int) const;
        void move(int,int);
    private:
        int start_peg,end_peg,peg_number;
};

towers(size_t n)
{
    assert(1<=n<=64);

    int i;

    for(i=0;i<0 && peg_number<4);
}

size_t top_diameter(int peg_number)
{
    assert(peg_number>0&&peg_number<4);
}

void move(int start_peg, int end_peg)
{
    assert(start_peg>0&&start_peg<4);
    assert(many_rings(start_peg)>0);
    assert(end_peg!=start_peg);
    assert(top_diameter(end_peg)>=top_diameter(start_peg));
}