ECE 1021

HOMEWORK #4

(Last Modified: 27 Nov 2010 )

PROGRAM A - Digitwise Math

Programming Problem #6.12 (p299).

Some people are invariably going to asks if it is okay to convert the string of single digit values to equivalent integers, add them, then convert them back to a string of single digit values. The answer is: no, this is not okay. Doing so totally defeats the purpose of the problem which to introduce you to the notion of high precision math where you need to use existing capabilities and limitations in order to perform operations that require greater capabilities. For instance, what if you needed to work with floating point values having more than 19 significant digits (the limit of long doubles on the Borland Turbo C/C++ v4.5 compiler) or integers having more than 32 bits? How would you perform multiplication and division of 24-bit fractional values using a processor that only supported 8-bit addition and subtraction of integer values? What you do is break the problem down (sound familiar) until you get it resolved into pieces that, individually, can be performed within the capabilities and limitations of the resources you have available.

Your basic limitation for this problem is that you can only add and subtract single digit values plus you can detect if such an operation results in a carry or a borrow. Think of the most basic way that you add multi-digit values by hand. What do you do? That's the basic approach your program should take.

PROGRAM B - The Game of Life

Programming Problem #6.18 (p300).

MODIFICATION: There are many variants on the game of life, most having to do with the boundary conditions. The authors have given boundary conditions that state that the neighbors of an edge cell are only those cells immediately adjacent to it and therefore it has only five neighbors while corner cells only have three neighbors. Imagine taking a piece of graph paper and rolling it into a tube, now the "edge" cells still have eight neighbors because the grid "wraps around". One of the most common implementations of The Game of Life approximates a spherical world by having the left edge wrap around to the right and the bottom edge wrap around to the top. Write your program using these boundary conditions.