Vectors (team assignment)

Overview

Python, Java, and many other languages have the capability for an array that automatically expands itself as necessary. In Python it is called a "list"; in Java, it is called an "ArrayList"; generically, it tends to be referred to as a vector. C has no such built-in vector capability, though it does have fixed-size arrays. For this assignment, you will implement a vector in C.

We'll again be using git and GitHub for this assignment. This time most of you will be working with a partner. If you are working in a team, look for a repository named "team??-vector", where the ?? is a team number. If you're working individually, look for a repository with your GitHub username, followed by a hyphen and "vector". (In both cases, you may first need to select "carleton251-term" in a dropbox near the top of the screen to see your course repositories.) If you are working on a team, I have also created for you an individual repository. Ignore it. Those individual repositories for those working on teams are only there for you in the unlikely event that you and your partner have to split ways and work individually. In the rare but possible case that this happens, I wanted those repositories to be there for you so you could use them without having to chase me down first.

Once you've found your project, clone it from GitHub. Within that project, obtain and put in these three files:

Use git to add, commit, and push them to GitHub.

Your assignment is to add to the file vector.c, which should contain the implementations for all of the functions prototyped in vector.h. Make sure to read the comments in vector.h carefully and follow all of the instructions.

Part 1

Implement the functions init, print, insert, and cleanup. Don't bother yet with making the array automatically double. To make sure that your code runs, modify tester.c so that the initial array size is large enough for the rest of the program (setting it to 100 initially will do it.)

Here's how to get your code to compile: type

clang vector.c tester.c -o tester

which will create an executable file called tester which you can then run:

./tester

We will be using clang to test your code, so you should do the same. Make sure that you do not have any compiler errors or warnings under clang (warnings are often a sign that you have a bug, anyway!).

When you have completed part 1, make sure that you have added any new files (including vector.c) with git, and that you have committed and pushed your changes. Using the same tag technique that you used in the lab, add the tag vectorpart1, and then commit and push the tag.

Part 2

Implement get and delete, and implement auto-doubling as well.

Valgrind

Your code should have no memory leaks or memory errors. We'll be testing this under the virtual machine using "valgrind", which is a wonderful tool for detecting memory bugs in C. Valgrind is an open source tool that is available for Linux and for OS X; unfortunately, it isn't available for Windows. (Tools like valgrind do exist for Windows, but they are quite expensive. Likewise, the Mac version mostly works but has some annoying glitches; which is why you'll want to run this on the department virtual machine.)

To use valgrind, first compile your code with debugging info enabled:

clang -g vector.c tester.c -o tester

You then run your executable through valgrind as follows:

valgrind --leak-check=full ./tester

You should see reports for every leaked block of memory, including file and line information for when the allocation happened.

When you have completed part 2, make sure that you have added any new files (including vector.c) with git, and that you have committed and pushed your changes. Using the same tag technique that you used in the lab, add the tag vectorpart2, and then commit and push the tag.

Additional info on submittions

If you are working with a partner, only one of you needs to submit; however, both of your names should be listed in the comments at the top of the file.

If appropriate, please also include a file credits.txt listing anyone other than me who helped you with the assignment, and any websites, books or other sources you used for reference. Please try to be thorough; in particular, if you had more than a passing interaction with another student, list them.


Assignment written by Dave Musicant, with some updates and improvements by Laura Effinger-Dean.