CSSE 120 -- Intro. to Software Development

Homework 28

  1. Don't forget to refer to the Python vs C comparison document. You may find this helpful as you try to do things in C that you already know how to do in Python. Feel free to suggest things that we might add to this document.
  2. There is no Angel quiz for the next session.
  3. 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.

  4. (2 points) In the source file main.c, edit the initial comment to include your name and today's date.
  5. 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.

    1. (9 points) Implement makeIntArray(), printArray(), and freeIntArray(). We will begin these together in class.
    2. (6 points) Make sure your "constructor", printing, and freeing work for a range of sizes, including size 0.
    3. (5 points) Implement makeZeroedIntArray().
    4. (6 points) Implement 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.
    5. (4 points) Add bounds checking to 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.
    6. (15 points) Implement pascalsTriangle().
    7. (10 points) Implement resizeIntArray().
    8. (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.

    9. (3 points) Reflection. On the next homework, we will extend the idea of SmarterArrays to create lists that have more of the capabilities of lists in Python. Think about how you might change our 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.
    10. Before submitting your final version, uncomment the 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.