Tower of hanoi

16
TOWER OF HANOI SOFT WARE LAB PROJECT REPORT

Transcript of Tower of hanoi

Page 1: Tower of hanoi

TOWER OF

HANOI

SOFT WARE LAB

PROJECT REPORT

Page 2: Tower of hanoi

SUBMITTED TO:Sayed Monower HossainLecturerDepartment of Computer Science And Engineering.University of Dhaka.

SUBMITTED BY:Iffat AnjumRoll: 16.Mohammad Maruful Haque Roll:37.Abdullah Al - MatinRoll:23.

Batch:15.

SUBMISSION DATE:04/03/2010.

Page 3: Tower of hanoi

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.

Page 4: Tower of hanoi

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.

Page 5: Tower of hanoi

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.

Page 6: Tower of hanoi

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);

}}

Page 7: Tower of hanoi

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.

Page 8: Tower of hanoi

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 .

Page 9: Tower of hanoi

Now we showing the steps of the replacements. for easy going we taking three disks. We need seven moves here.

THE FIRST MOVE:

Page 10: Tower of hanoi

SECOND MOVE:

Page 11: Tower of hanoi

THIRD MOVE:

Page 12: Tower of hanoi

FORTH MOVE:

Page 13: Tower of hanoi

FIFTH MOVE:

Page 14: Tower of hanoi

SIXETH MOVE:

Page 15: Tower of hanoi

SEVENTH MOVE:

Page 16: Tower of hanoi

Reference books :1.ANSI C++

( E Balagurusamy)3. Graphics under C

(Yashavant Kanetkar)

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