Vectors

Table of Contents

This is a “pair” assignment, which means that if you are working on a team with someone else, you and your partner should do your best to engage in the pair programming model. If at all possible, my recommendation is to use Repl.it, which will allow you to code together remotely using “multiplayer” mode. At any point in time, one of you is “driving,” i.e. actually using the keyboard and mouse. The other is actively engaged following along, preventing bugs, and providing ideas. You can communicate with each other via Google Hangouts, Zoom, a phone call, or any other voice approach. In a pinch, you can also use the Repl.it chat window, though having voice communication with each other would be better.

You should make sure that over the course of an assignment that you spend roughly the same amount of time each “driving.” I will also ask you to turn in a form rating the work that your partner does. My recommendation is to take turns approximately every 15 minutes or so. Set a timer to help you remember.

If pair programming in real-time just doesn’t work for you and your partner, you have options:

1 Get started

1.1 Use GitHub classroom to create a repository for your assignment

The first thing you’ll need to do is to create a repository for your project using GitHub classroom. If you are working on a team, this repository will be shared, so only one of you should do this. To help reduce a round of communication, I’m going to designate that if you are working in a pair, the member of your team whose Carleton official email address comes first alphabetically should do this next step of setting up the GitHub repository. This is opposite from the previous pair assignment; I’m trying to give everyone an equal chance to participate. If you are working alone, then you should do this step.

If you are the designated person above, visit this GitHub classroom link (which I’ve placed in Moodle). Log into GitHub if your browser prompts you to after you get to GitHub. You should be taken to a screen that invites you to either “Join an existing team” or to “Create a new team”. Pick the team that you created for the last team assignment. GitHub should then hopefully respond with a screen that says “You are ready to go!” and supplies you with a link for the repository that you are creating.

Before you click that link, look below it to see text that says “We’ve configured the repository associated with this assignment (update).” The word “update” is a hyperlink: click it. Then, click on the link to the repository itself, and you should be taken to the repository.

Click on that link, and you should be taken to the repository. If you’ve gotten this far, you have successfully created the repository, and you the user who is logged in have access to it. Contact your partner if you have one and tell them that this step worked. (If you are working alone on the project, you can skip the next step.)

The other one of you, after the above is complete, should visit the same GitHub classroom link in the first sentence in the previous paragraph. You’ll see the screen asking you to “Join an existing team” or to “Create a new team.” You should be able to see the team that your partner created above; click the “Join” button. This should then take you to the “You are ready to go!” screen, and you can hopefully find a link to the repository. Click on it. You now both have access to the same GitHub repository.

1.2 Create a repl in Repl.it

1.2.1 Approach 1, if the “Work in Repl.it” button is working again:

Once you see your repository in GitHub (not Repl.it), you should see a button labeled “Work in Repl.it.” Click it. That should set up a new repl in Repl.it, and you should be all set to work. As always, make sure the repl created in Repl.it is private.

1.2.2 Approach 2, if the “Work in Repl.it button” is not appearing in GitHub:

In Repl.it, create a new repl. There are multiple places you can do this from. At the home screen, I see a blue plus in the top right corner; I can also access it by opening up the left sidebar menu via the “hamburger” menu on the top left. After clicking on “New repl” (or the blue plus, or whatever), you should get a popup with two tabs. The left tab says “Create new repl”; the right tab says “Import from GitHub”. Click “Import from GitHub.” You then see a box with the title “Paste any repository URL.” Then go to GitHub, specifically, to the repository you created in the previous section. Copy the entire web address from GitHub, and paste it into Repl.it. The URL you are copying should look something like

https://github.com/carleton251-f20/vector-username

(where username is your username)

When you paste it into Repl.it, it will abbreviate it a bit for you.

Then click “Import from GitHub.” This then creates the repl as usual. As always, make sure the repl created in Repl.it is private.

… and you should be all set to work.

2 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 or a dynamic array. 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.

In the repository that you have cloned, your assignment is to add to the file vector.c. Specifically, you should add 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. Make sure to change only vector.c and leave the other files untouched.

3 Part 1

Implement the functions init, print, insert, get, and cleanup. Don’t bother yet with making the array automatically double. You will need to make sure you have minimal stub code in the remaining functions to make it compile.

As usual, you can test your code for correctness with the test scripts ./test-m and ./test-e. 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 valgrind, which is a wonderful tool for detecting memory bugs in C. If valgrind produces error 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.

When you have completed part 1, make sure that if for some reason you added new files that you have added them with Git, and that you have committed and pushed your changes. Your commit comment should be SUBMITTED-PART1 (which an M or E prefix, as usual.) GitHub will run tests for both part 1 and part 2. If you have not yet completed part 2 yet, GitHub will show a red X for the tests failing, but if you look at the details you should be able to see the part 1 portion passed.

4 Part 2

Implement any remaining functions that you skipped in Part 1, and implement

4.1 Submitting

When you have completed part 2, make sure that you have added to Git any new files, and that you have committed and pushed your changes. Using the same tag technique that you used in the lab, add the commit comment SUBMITTED-PART2, with an M or E prefix as usual.

5 Capstone work

Work in this section is 100% optional, and doesn’t contribute towards your grade. Nonetheless, if you’re looking for an extra challenge, these are fun additional exercises to try.

Duplicate vector.h and vector.c to create two new files, stringvector.c and stringvector.h. Instead of holding integers, this new vector will hold C strings, i.e., arrays of characters. Create a new set of tests to test it out. Whenever you add a string to your vector, make sure that you make a copy of it. The assumption we’ll make for this assignment is that the vector is then responsible for cleaning up any strings added to it.


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