You must do this assignment using Eclipse and the SmarterArrays project that you checked out from your individual SVN repository in class.
Be sure that you checked out that project into your Eclipse C workspace, not your Python workspace.
Stubs for all of the functions have been provided for you in main.c. The file also contains specifications of each function as comments.
We've provided all of the test code in the functions
main()
and
runTests(). We've included
return
statements before each test so that you can get one set of tests working before moving on to the next.
The file
expected.txt
in the project gives the expected output for parts a through g. You can use it to check your work. Note that some of the values printed are uninitialized, and so will be different on your computer and between runs.
You are to complete the definitions of all of the functions below. The tests are written expecting that you will complete them in the order listed. For each part, you'll need to comment out a
return
statement to allow the tests for that part to run. Be sure to commit to your repository as you finish each function; that will help us to award credit for each function that you finish.
makeIntArray(),
printArray(), and
freeIntArray(). We will begin these together in class.
makeZeroedIntArray().
set()
and
get()
functions for mutating and accessing
IntArrays. For this part, you do
not
need to check to see that the indexes are in bounds (i.e., non-negative and not larger than the array size). Your functions should initially return
FALSE.
set()
and
get(). Your functions should print an error and return
TRUE
if an out-of-bounds index is passed to the function, and return
FALSE
otherwise.
pascalsTriangle().
resizeIntArray().
(5 points)
Stress tests.
Comment out the
return 0;
statement in the
main()
function. This will allow a memory stress test to run. The stress test calls your
pascalsTriangle()
function with larger and larger values, doubling in size each time. If your program has a memory leak, this stress test will detect it.
You will probably want to comment out the body of
printArray()
for this test also, otherwise your program will spend lots of time printing and it will take much longer to reach large memory sizes.
In our tests, when we failed to free memory correctly in
pascalsTriangle(), the program "died" at a stress test size of 40960, with the error message
unable to allocate enough memory for array of size 22563. Without the memory leak, our program made it to a stress test size of over 2.6 million before we stopped it.
Add a comment near the end of
main()
indicating how large a stress test size your program reached.
IntArray
struct so we could create initially empty
IntArrays and
append
to them. Don't change your code, but add a comment near the end of
main()
describing what you might do.
return
line before the stress test, to keep the stress test from running. Also uncomment the body of
printArray()
so the grader can check the functionality of your functions. Commit your final version to your SVN repository.