Programming assignment #2, Due: January 25

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


Classes and object-oriented programming

If I changed the image data structure used in ImageLib.h and ImageLib.lib, all of the code that uses these files would need to be changed. Your goal for this program is to create a C++ class for images that hides the details of the image data structure. If the data structure is changed, only the details of your image class should need to be changed (and not the interface), so that other code that uses the image class can be used unchanged. This will also upgrade images to first-class objects with a constructor, destructor, operator=, etc. Make sure that you use the concepts of data abstraction, information hiding, modularity, and fail-safe programming whenever possible. 



You are to create a new class representing images. Remember that your project should be created as an “Empty project,” so that you don’t get precompiled header code among other things. In order to create this class you should continue to use the files for working with images from the previous programming assignment:


If you want a new test image, you can use this one:



The assignment has two parts. First, you will play the role of class designer and create a new class for images. Second, you will play the role of developer using the class you wrote. For the second part, you should use your class, but not make any assumptions about the implementation of the class (and don’t write new member operations to solve that part).


Your image class should include (at least) the following capabilities. Use my image library as much as possible to make these simple. For example, store an image variable in your private data. Use ReadGIF to implement the first constructor, etc.



Now, using your image class (and without writing any more methods), write a driver (main method) that performs the following operations. These are similar to Program 1, except that you should use the interface provided by your class and not use ImageLib directly.


1.   Read the image “test.gif”.

2.   Output the number of rows and columns using operator<<.

3.   Create a rotated image using your member function (use this image as the input to step 4).

4.   For every pixel, subtract green mod 15 from the blue component and add col mod 13 to the red component. Continue to check for (and correct) overflow and underflow.

5.   Write the image as “output.gif” and read that file back into a new variable.

6.   Compare the image that you wrote to the image read in the previous step using your == operator for images.

7.   If the images are different, count the number of different pixels.

8.   Output the number of differences.


Note that this will not use all of the methods that you wrote, but I will still look at ones that are not used for errors. For steps 4 and 7, do not write new methods. Use the accessors and mutators specified in above.


You generally won’t want to pass an image parameter by value, since this results in copying the entire image. Passing by reference (using const when possible) is better.


For additional fun (optional)

Implement additional methods that operate on images. Some that you might try:



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.