Matrix Cover

Program Specifications

Create a program consisting of a single source code file named array_cover.c and submit it in a directory named cover.  Please be mindful of the spelling and case of the source code file name and directory name specified above as I will be testing your code using a script.

Your source code file must contain:

  • A comment at the beginning of the file that states your name and the date it was last modified
  • Proper style, including proper variable names and indentation

Your program must accept 3 command line arguments in the order that follows:

  1. an integer k specifying the dimensions of a k x k matrix
  2. an integer i in the interval [0 , k x k)
  3. an integer specifying and id

The program should allocate on the heap a single dimensional array of integers of length k x k and free it before terminating.

After allocating the array, your program should initialize all of the integers to 0 using memset and set the integer at index i to the value id.

After initializing the array the program should print the contents of the array as a k x k matrix to the console using a function named print_matrix.

In the remainder of this program description we will view the array as a k x k matrix and refer to it as such.

The program should set all of the elements in the matrix to the value id while satisfying the following constraints:

  • If the program changes the value of a matrix element, the program must print to the console the contents of the matrix before changing the value of another element in the matrix.
  • You may only change the value of a matrix element if one of the cells adjacent (including those on the diagonal) to the element about to be changed has the value id.

Grading Rubric

To assess your program, I will run your program with various inputs. I will change the dimensions of the matrix, the index where you’ll initially put your id, and I’ll change the value of the id.  Below is the grading rubric which I will use to assign you a grade.

100  Satisfies the program requirements and passes all of the test cases
 80  Satisfies the program requirements but fails at least 1 test case
 60  Satisfies the program requirements but fails all tests
  0  Does not satisfy the program requirements

© 2019 – 2020, Eric. All rights reserved.