Programming assignment #3, Due: February 8

CSS 342 - Data Structures, Algorithms, and Discrete Math I – Winter 2018


Classes, recursion, and image fractals

In this program, we are going to use recursion to create a type of image fractal. The image class you created for the previous program will be used with recursion in a non-trivial fashion to create a new image similar to the one below.


      Input image:                                                                                  Output image:

test       output



Using your image class, you should read in an image called “test.gif” and output an image called “output.gif.” You may change your image class if you want, but you should NOT write a class method that creates the fractal or shrinks the image. You should only use the accessor and mutator functions from your class. Your output should look like this:




You should (once again) use the image library from the course web site. Whether you change it or not, please turn in your image class from Program 2 again with your code for this program.


Here is another test image:


See the assignment page for an example that is 256x256 for testing (but your code should work with any size).


Write a new class

For full credit, you must write (and use) a new Rectangle C++ class as part of this assignment. For this assignment, your rectangle class will store the boundaries of a region in an image (but it should not be limited to this use). For example, you might store the first row/column and the number of rows/columns (or the last row/column).

It should not store any image data – it is just bookkeeping the current region boundaries. Your class should have constructor(s), accessors, and mutators. Overload operator<< to output the information in human readable form (whether you use it or not). Also, overload operator== and operator!=. You may add additional methods if you like. Do not use dynamic memory in this class (the compiler supplied copy constructor, destructor, and operator= will be fine in this case, so you won’t need to write them). You will use this class in your recursive method to keep track of the current region of interest and pass new values in recursive calls as the regions change.

Summary of required methods: constructor(s), accessors, mutator(s), operator<<, operator==, operator!=



Use the following specification exactly to get full credit.

output(r, c) = (input(2r, 2c) + input(2r+1, 2c) + input(2r, 2c+1) + input(2r+1, 2c+1) ) / 4

Always round down (integer division is fine).

output(r, c) = (input(maxR – 2r, maxC – 2c) + input(maxR – 2r – 1, maxC – 2c) +

input(maxR – 2r, maxC – 2c – 1) + input(maxR – 2r – 1, maxC – 2c – 1) ) / 4


For additional fun

Create other interesting fractal patterns using recursion.



This program is worth 25% of the programming score for the course. See the grading rubric for a breakdown on how each program is scored.