1 / 12

Project 2

Project 2. Towers of Hanoi. 1. Towers of Hanoi. Towers of Hanoi is a well known puzzle that can be very difficult to solve manually but can be programmed very easily with a recursive solution. http://en.wikipedia.org/wiki/Tower_of_Hanoi

parson
Download Presentation

Project 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Project 2 Towers of Hanoi 1

  2. Towers of Hanoi • Towers of Hanoi is a well known puzzle that can be very difficult to solve manually but can be programmed very easily with a recursive solution. • http://en.wikipedia.org/wiki/Tower_of_Hanoi • Write a C# console application to show the moves to solve the puzzle for an arbitrary number of disks. • Call the pegs A, B, and C. • Let the user specify the number of disks. 2

  3. Specifications • Get the number of disks from the user. • Require the number to be greater than 0 and no more than 10. • Start with all disks on Peg A • Output a message describing each move. • After each move show the configuration of the pegs. • Your output should match the sample runs for the same input.

  4. Character Graphics • Represent disk n by a string of 2n-1 X's X XXX XXXXX XXXXXXX Example: A stack of four disks.

  5. Sample Run Continued on next slide.

  6. Sample Run (continued)

  7. Sample Run

  8. Specifications • Define a class to represent a peg and the disks stacked on top of it. • Essentially identical to a stack. • Each Peg should have a name, consisting of a single character. • Enforce the constraint that you can't put a larger disk on top of a smaller one. • Throw exception on violation of this rule or stack overflow. (Shouldn’t happen)

  9. Specifications • Avoid throwing an exception on invalid input. • Use int.TryParse() to convert strings to ints. • Make your output match the sample runs.

  10. Ground Rules You may work with one other student. OK to work alone if you prefer. If you do work as a pair Work together! Both members are expected to contribute. Both members should understand the program in detail. Submit a single program. Do not share your code with other students. Before or after submitting the project. OK to discuss the project. Do not copy any other student’s work. Don’t look at anyone else’s program. Don’t let anyone look at your program. 10

  11. Ground Rules Except for code posted on the class web site Do not copy code from the Internet or any other source. Write your own code. 11

  12. Submission • Project is due by 11:59 PM, Wednesday, Jan. 26. • Late projects will not be accepted. • Deliverables: • Zipped project folder. • Use the Windows "Send to Compressed Folder" command to zip your folder. • Submit your file via Blackboard Assignments. • Not Email • If you work with another student, include both names in the submission comments. • Other student submit Blackboard comment with both names. End of Presentation 12

More Related