Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

SOFT WARE LAB

PROJECT REPORT
TOWER OF
HANOI
SUBMITTED TO:
Sayed Monower Hossain
Lecturer
Department of Computer Science And Engineering.
University of Dhaka.

SUBMITTED BY:
Iffat Anjum
Roll: 16.
Mohammad Maruful Haque
Roll:37.
Abdullah Al - Matin
Roll:23.

Batch:15.

SUBMISSION DATE:
04/03/2010.
TOWER OF HANOI :
Tower of Hanoi or Towers of Hanoi is a mathematical
game or puzzle. It consists of three rods, and a number of disks of different sizes
which can slide onto any rod. The puzzle starts with the disks in a neat stack in
ascending order of size on one rod, the smallest at the top, thus making a
conical shape.
OBJECTIVE OF TOWER OF HANOI:

The objective of the puzzle is to move the entire stack to


another rod, obeying the following rules:

* Only one disk can be moved at a time.

* Each move consists of taking the upper disk from one of


the rods and sliding it onto another rod, on top of the other disks that may
already be present on that rod.

* No disk can be placed on top of a smaller disk than itself.


OBJECTIVE OF THE PROJECT:
In this project our main goal is to take number of
disks from the user to show how the concept of tower of Hanoi works .

In this project we show how the disks replace from


the first tower to the 3rd tower without placing the larger disks over the smaller
disks.

For showing all this facts we have used mainly the


glut.h and also iGraphics.h….

We have mainly used iGraphics for the project.

And used recursion formula for indicating the


placements.
We have used recursion formula for solving tower of
Hanoi……..
void tower(int n,int sr,int md,int ds)
{
if(n==1)
{ a[p++]=sr;
b[q++]=ds;
}
else
{
tower(n-1, sr, ds, md);
a[p++]=sr;
b[q++]=ds;
tower(n-1, md, sr, ds);
}
}
THE FUNCTIONS :

We have used void DrawRectangle (rect A, int x) for drawing rectangle shape
of the piles.

We have used void initPile() to determine height,width & placements of the


piles.

We used void mvup() to move piles up-ward.

We have used void mvside() to move the piles sidely.

We have used void mvdown() to move the piles down-ward.

We have used void iDraw() to draw the graphics.


THE FUNCTIONS :
We have used void iMouse(int button, int state, int mx, int my) for
controlling over mouse movement.

We have used void iKeyboard(unsigned char key) to control over Keyboard.

iInitialize() to determine the window size & the name of the programe.

tower(int n,int sr,int md,int ds) to save the movement of piles in array.

int main() is the main function that calls all the functions we have used .
Now we showing the steps of the replacements. for easy going we taking three
disks. We need seven moves here.

THE FIRST MOVE:


SECOND MOVE:
THIRD MOVE:
FORTH MOVE:
FIFTH MOVE:
SIXETH MOVE:
SEVENTH MOVE:
Reference books :
1.ANSI C++
( E Balagurusamy)
3. Graphics under C
(Yashavant Kanetkar)

Acknowledgement :
www.google.com.bd/
www.cplusplus.com
www.cse.univdhaka.edu/~cse102/

You might also like