Programming assignment #1, Due: January 11

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


Programming with images in C++

This program is an introduction to programming with images and ensures that you have some of the programming background necessary to succeed in this course. The programming aspects of this assignment shouldn’t be difficult. If you find yourself spending several hours on it, you should consider taking another programming class to brush up on your skills. Even though this is a short program, you should still make the program modular and use fail-safe programming.


We will be using Visual Studio 2017. It is available in the Windows Lab (UW1-310) and the Community Edition can be freely downloaded from:  



  1. Post an introduction on the Introductions thread on the message board.


  1. Create a new C++ project in MS Visual Studio called “Program1”.


The project should be a Visual C++ - General - Empty Project. Remember where you save the project. If your project has stdafx.cpp or stdafx.h or targetver.h, then you did this incorrectly. Your code should compile without these files and you should not turn them in.


  1. Download the following files from the web and place them in …/Program1/Program1/

Do not change the contents of these files in order to complete this assignment.


  1. Examine ImageLib.h to understand the interface for reading and writing GIF images. You should not be able to access the implementation details of ImageLib.lib. Note that images are not first-class objects. For example, there are no constructors or assignment operators that will handle them correctly. Functions are provided in the library for these purposes.


  1. Add ImageLib.h and ImageLib.lib to your project (Project – Add Existing Item).


  1. Create a new source file in Program 1 called main.cpp (Project – Add New Item). We are now ready to start coding.


  1. Edit main.cpp to accomplish the following in order:


    1. Read the image test.gif.
    2. For every pixel of this image:

                                                        i.   Subtract green mod 15 from the blue component of the pixel, where green is the green component of the pixel. The mod operator uses the % symbol.

                                                      ii.   Add col mod 13 to the red component of the pixel, col is the column of the pixel.

                                                    iii.   Do not change the green component of the pixel.

Check for overflow and underflow, since bytes are unable to store values below 0 or above 255! If you find overflow, set the byte to 255. If you find underflow, set the byte to 0.

    1. Create a new image that is the image from the previous step rotated by 90 degrees counter-clockwise. The number of rows in the new image will be the number of columns in the previous image (and vice versa).
    2. Save the new image to a file called output.gif.
    3. Read output.gif into a new image variable.
    4. Compare each pixel in the newly read image to the one that you saved in step d (not the original). Are there any differences?
    5. Count and output to the console the number of pixels that have different values for red, green, or blue. (If a pixel has a difference in any of the three, then it counts as one difference.)


  1. Submit your completed code (only new code that you wrote, as few as one file) using Catalyst at:  



For additional fun (optional)




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