Machine Problem 4, due November 3

Part of the homework for 22C:60, Fall 2008
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Submit the source file mp4.a (or mp4.txt if you must) for your solution to ICON on or before the indicated date.

The Problem

|___|   |___|        |___|        |___|         |
| | |   | | |        | | |        |   |         |
  |_______|            |
  |       |            |
|_|_|   |_|_|        |_|_|
|   |   |   |        |   |
The above figure shows 4 H-trees. On the left is a 4th-order H-tree, while on the right is a 1st-order H-tree. H-trees are an example of a fractal figure. Each higher-order H-tree is composed of two of the next-smaller order H-trees connected by a line. These H figures are formed of ASCII characters, underlines for the horizontal elements, vertical bars for the vertical elements.

Write a recursive subroutine haich(x,y,n) that plots an n'th order H-tree centered (as much as is possible) at location x,y on the screen. (Hint: Mutual recursion of two different H-tree routines may be a good idea here, one that draws its subtrees vertically, one that draws them horizontally.)

And, write a main program that calls haich() to plot the largest H-tree that will fit on the screen, centered on the screen.

You will need to research the following questions in order to get started writing this program:

Note, the Hawk emulator will run in any size terminal window, but you must resize the window before launching the emulator. If you set the font size very small and stretch the window large, you can plot some huge H-trees.