Assignment 1 CMPT 125
This assignment consists of two problems.
For the first problem you will submit a file with the name Sier.c, for the second problem you will
submit a file Mastermind.c.
80% of each problems mark will be based on running tests (see next paragraph for details) and
the remaining 20% will be for specific specifications of the code in the problem that are not
testable by running the code. For example, did you correctly allocate and deallocate dynamic
memory rather than using automatic arrays, or did you properly clean up before each place the
code is terminated.
Each problem will be graded by comparing the output produced by your program to the
reference solution. The given error messages should be used, and the outputs in the test plan
should be matched character by character by your output to receive all points. Parts of the
outputs of the tests will be chosen for grading. Points will be allocated only for those chosen
parts. Each part of the output chosen will represent a requirement stated in the description of
the problem. Some of the tests provided to you in the test plan will be modified by changing
input values and used for grading. Not all functionalities of the program are tested in the
provided test plan. Some additional functionalities not tested in the provided test plan will be
graded using additional tests.
PROBLEM 1 (40 points): You will generate a pattern called a Sierpinski gasket on a board of
M by N squares (M<80 and N<40). The board will be represented by a 2-D array. You should use
the exact prompts and error messages specified in the test plan below in your code. Outputs of
your code will be checked for character-by-character correspondence to the sample outputs.
You may assume that the data entered by the user using the keyboard is of the correct type
(integer, double …), but you must check that the values are in the correct ranges. You must also
check if the data in the input file is of the correct type and in the correct range.
1) Include and use a function for setting all elements in a 2-D array of size M rows by N columns
to 0. This function should have the prototype
void FillZero( int ** my2DArray, int M, int N);
2) Include and use a function to do a deep copy of the elements in 2-D array myNextGenArray
of size M rows by N columns into 2-D array my2Darray of the same dimensions. This function
will have the prototype
void CopyArray(int ** my2DArray, int**myNextGenArray, int M, int N);
This function must be implemented using pointer arithmetic.
3) Include and use a function for Calculating the next generation array. This function should have
the prototype below. In that prototype board is the 2- D (M by N) array holding the game
board. The requirements of this function are discussed later.
void NextGen(int ** board, int M, int N);
4) Include the following steps in the main program.
a. Prompt the user for the name of an output file using the prompt:
Enter the name of the output file:
b. Open the output file and check that it has been opened correctly. If the output file has
not been opened correctly print the error message below, clean up as necessary and
terminate the program.
ERROR: Input file not opened correctly.
c. Open the input file and check that it has been opened correctly. If it has not been opened
ERROR: Output file not opened correctly.
d. Prompt the user for the number of rows in the game board using the prompt:
Enter the number of rows in the board (0