600.120 Intermediate Programming
Summer 2013 -- Assignment 6
Due by 9am on Friday, 6/21
Color Class [30 points]
Define a Color class which can be used to manipulate RGB
colors in integer, rgb and hex forms. Your class must support the
test program ColorTest.cpp exactly as
given. Create your solution in two files: Color.h and Color.cpp.
Include a rule to make a "colorTest" executable in your makefile.
Board Template Class [40 points]
Create a templated 2 dimensional Board class that could be used for a
variety of applications including many games such as Checkers, Sudoku,
Scrabble to name a few. The template part is the data type of each
cell on the Board. We will assume that the stream input and output
operators (<< and >>) are defined for any cell type that might be used
with a board. We will also number the rows and columns starting
with 0 in the top left corner of the board so as to have a
consistent way of referring to each cell.
In addition to its value, each cell has a
background color and a foreground color, which can be used when
converting the board into an html format for display.
You must have the
following functions in your class:
- [5]
A constructor that could be passed one or two integer parameters
indicating the board dimensions (rows and columns, respectively).
If only one dimension is passed, then create a square board. The
default background color for each cell should be white, and the
default foreground color should be black.
- [5]
A deep copy constructor that creates and returns a full copy of this
Board.
- [5]
A function called "htmlTable" that has no parameters, but returns
a C++ string that contains all the html tags and content necessary
to display the board, including the cells' background colors. (You
will need to look-up stringstreams in C++ to implement this.)
- [3]
A function called "setBackground" which takes a Color object, row
and column indices, and updates the background color for the corresponding
cell if the row and column values are valid. Return true if
successful, false otherwise.
- [3]
A function called "setForeground" which takes a Color object, row
and column indices, and updates the foreground color for the corresponding
cell if the row and column values are valid. Return true if
successful, false otherwise.
- [3]
A function called "setCell" which takes a cell type value, row
and column indices, and updates the cell value for the corresponding
cell if the row and column values are valid. Return true if
successful, false otherwise.
- [2]
A function called "initBoard" which takes a value of the cell type and
uses it to initialize all the cells. This could be used to clear the
board for example.
- [2]
A function called "getCell" which takes row and column parameters and
returns the object which is the value stored in the corresponding
cell. Throw an exception if either parameter is invalid.
- [2]
A function called "getCellReference" which takes integer row and column
parameters and returns a reference to the value stored, so that it can
be modified. Throw an exception if either parameter is invalid.
- [5]
A function called "getSub" which takes two sets of position indices
(row, column pairs) - 4 integer parameters total - and returns a Board
which is a subset of the original board. The first two parameters
should be the row and column indices for the top left corner of the
subgrid and the next two are the coordinates for the bottom right
corner. Throw an exception if any parameters are invalid. (This
function could be quite useful if you are using the board to play a
game like Sudoku where you need to operate on a row or a column or
some other subset.)
- [2]
A destructor which frees all the memory that has been allocated for
the board.
You must use dynamic memory allocation to create your board, and
must not have any memory leaks. Your class must support our test
program BoardTest.cpp.
Makefile [5 points]
Write a makefile for all parts of the assignment with rules for
colorTest and boardTest, and an all
which creates both.
Submission & Grading
Only submit printouts of the files that you wrote, not our test
files. Make sure everything is included in your submitted zip file.
| Color Class | 30 |
| Board Class | 40 |
| Makefile | 5 |
Memory leaks/errors: -5 points, compiler warnings: -5 points
General assignment requirements, style and submission details:
Sunday, 14-Dec-2025 00:36:55 EST