Assignment 8 - Vectors 1
Due: Monday, April 20, 2026, at 10pm
Starter code: a89_vector.zip
Upload solutions via Gradescope
Goals
This assignment is designed to help you with the following:
- working with arrays, structs, and pointers in C
- using header and code files to separate out function signatures and implementation
- working with larger code bases in C
Collaboration policy
For this assignment, you may work alone or with a partner, but you must type up all of the code yourself. (It is therefore unexpected for two code submissions to be completely identical.)
You may also discuss the assignment at a high level with other students.
You should list any student with whom you discussed the assignment, and the manner of discussion (high level, partner, etc.) in your readme.txt file.
If you work alone, you should say so instead.
Assessment
This assignment is broken into two parts. For each part, there are CR and AD test cases. For this assignment you’ll implement the base functionality, which you will build on in Assignment 9.
Core requirements:
- all
CRtests pass - a visual inspection of your code shows that you have not hyper-tailored it to pass the tests
readme.txtcontains your collaboration statement, sources, and reflection
Note that hyper-tailoring in this case would be doing things like checking for the exact input from the test, meaning you haven’t written your code in a way that would work for other similar inputs.
Advanced requirements:
- satisfy the Core requirements
- all
ADtests pass - your code is not significantly more complex than needed to accomplish the task
- each function has a comment before it describing its high-level behavior
- your code uses good C coding style
Getting started
As before, you should download the starter files, unzip that file, and copy the folder to where you’ll work (probably your ProgrammingLanguages folder). Refer to the Assignment 1 instructions if you’re unsure what to do.
Assignment overview
Python, Java, and many other languages have the capability for a list impementation that uses an array that automatically expands itself as necessary. In Python it is simply called a list, in Java it’s an ArrayList, and in Kotlin it’s a MutableList. Generically, it is sometimes referred to as a vector or a dynamic array.
C has no build-in vector capability, although it does have fixed-size arrays. For this assignment, you will implement a vector in C. (Note that while C has so-called variable-length arrays, that only means that you can create an array whose size is given by a variable. It’s still the case that once the array is made, it isn’t automatically resized as needed.)
Your assignment is to add to the file vector.c in the starter code. You’ll eventually be writing code for all of the functions prototyped in vector.h. That means you’ll have the same functions as in vector.h (as well as any other functions you wish), with the same input and output types. These functions should have bodies (unlike in vector.h). make sure to read the comments in vector.h carefully so you know what each function should do, and follow all of the instructions in vector.h. You should change only vector.c; please leave the other files untouched–we will be using our versions of these files for testing, so if you make changes, your code may not pass our tests.
Part 1: Assignment 8
Implement the functions init, print, insert, get, and cleanup. For insert, you do not need to make the array automatically double yet (you’ll do this for A9 in Part 2).
To get started, make sure to have minimal stub code in the remaining functions so the program will compile. The easiest way is to copy all functions over to vector.c and have each either return; or return 0;, depending on their return types.
As usual, you can test your code for correctness with the test scripts ./test-cr and ./test-ad. If you want to see the tests themselves, the place to look is in tester.c.
Your code should have no memory leaks or memory errors. We’ll be testing this using valgrind, which is a useful tool for detecting memory bugs in C. If valgrind produces errors messages, this is considered incorrect, so it’s important that you check it yourself. The testing scripts automatically run valgrind on your code, so you’ll see those errors as well. Additionally, the test scripts will report failures if you have compilation warnings.
When you run the tests, it’s fine if you see a part like FAIL: testVectorPart2. What you don’t want is FAIL: testVectorPart1. For this first part, only the “Part 1” tests need to pass.
Part 2: Assignment 9
Head over to the Assignment 9 page to see what’s left.
Testing your work
This previously said there were only CR tests, but the requirements above clearly state there are both CR and AD tests – take a look at the test files to see what they expect.
As with previous assignments, there are CR and AD tests for core and advanced functionality. Look at the instructions from A2 if you want a refresher on how to run these tests.
The tests will also use Valgrind to check your code, so make sure to run the tests in the Docker environment.
Submitting your work
For this assignment, you will submit just one code file. You are strongly encouraged to run ./zipitup to use that script to gather your files for Gradescope.
C code
The file vector.c should contain your functions. Make sure to add a comment above each of your functions (including any helper functions you choose to write) to describe its behavior at a high level (e.g., what it takes as input and what it returns as output).
Readme
For each assignment for this course you will also need to submit a file readme.txt in which you should write:
- Your collaborations with anyone on the assignment
- Your use of any outside sources on the assignment
- Your reflection
You should be specific about your collaborations and sources – they shouldn’t just be empty or lists of names of people. If you worked alone and/or did not use any outside sources, you should say so.
For your reflection, spend a couple of sentences answering the following:
- Were there any particular issues or challenges you dealt with in completing this assignment?
- How long did you spend on this assignment?
Submitting to Gradescope
As always, use ./zipitup to gather your files. Submit the resulting .zip file to Gradescope at this link.
Note that it is possible (although unlikely) that the tests will pass on your computer but fail on Gradescope. If this happens, it’s probably because you coded something in an unusual way. Double-check that you’re submitted to the correct assignment and then check if any error messages can help you troubleshoot. If you’re still having issues, check with Tanya.