C++ Game Project | Tower Of Hanoi Using Stacks

Project Title: Tower of Hanoi Project in C++download tower of hanoi game in c++

Developed Under: Dev C++ 5.11

Data Structure: Stack

Object Oriented Programming: Yes

The Tower of Hanoi is a mathematical puzzle game. 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.The objective of the puzzle is to move the entire stack to another rod.

There are some rules which should be obeyed playing the game:

  • Only one disk can be moved among the towers at any given time.
  • A disk can only be moved if it is the uppermost disk on a stack.
  • No large disk can sit over a small disk.

Tower of Hanoi puzzle with n disks can be solved in minimum of  2n−1 steps. A puzzle with 3 disks takes minimum of 23 – 1 = 7 steps.

 Recommended reading: Airline Ticket Reservation System Project in C++

To download the C++ code of tower of hanoi, Click on the link given above.

The basic purpose of uploading the code on this website is that students can get knowledge from it. It helps them  in understanding the syntax, functions of the programming language.

Screenshots of Project Tower of Hanoi:

c++ project on tower of hanoi

c++ game on tower of hanoi

tower of hanoi game in c++


Features of Project:

The main features of this C++ program are:

Multi Level:

This game has 2 levels. Level1 contains 3 disks while level2 contains 4 disks. If you are an expert in level1 then you can move onto level 2 which is a bit difficult.

User Manual:

A user guide is included in the program which tells the user about the rules of game. A programmer is also recommended to read these rules before analyzing the code of program. A user can access these rules by pressing “1” in main menu.

Scoring System:

Like all other games, this game also has  a scoring system which computes the score based on the moves. If a person moves the disk many times to complete the puzzle then his score will get worse.

 Recommended reading: Static Functions: Access Member Function Without Object in C++

Stack Data Structure:

This program uses the stack data structure. This data structure is based on LIFO  i.e Last In First Out principle. For example, if you want  to get the computer science book, which is underneath your math and history books, you must first remove the math and history books to access the desired book. You can consider the 3 rods of this program as 3 stacks.

File Handling:

File handling is a crucial part in a program. This program uses file handling to store the scores. C++ code creates a .dat  file and stores “best scores” in it.

About Developer:Developer: Abu Bakar Ghori

Originally this program is written by my friend, Abu Bakar Ghori. He has a lot of interest in programming. He is studying Computer Science in University of Gujrat. He shared this project to help other students. This project is one of best projects made by him. I hope so that he will write more programs to upload on this website.

If you liked this article, then I would really appreciate if you follow us on Twitter and Facebook.

If you have any question then you can ask me in comments. I would like to answer them.

You can also Click Here To Download Project Files.