Lab 3: Big-Three Review and Getting Accustomed to Git

Due: 4/19 11:59pm

1 Goals

By the end of this lab, given a description of a class containing data members that point to structures on the heap, you will be able to:

  • write a correct copy constructor for the class
  • write a correct destructor for the class
  • write a correct assignment operator for the class

2 Getting Started

This lab may be done solo, or in pairs.

Before you begin working on the lab, please decide if you will work solo or with a partner. If you decide to work with a partner, read the Working in pairs section of the course webpage.

Once you and your partner are in agreement, choose an initial driver and navigator, and have the driver log into their account.

Before you begin working on the lab, please decide if you will work solo or with a partner.

3 Step-by-Step instructions to getting setup with git and GitHub

In case you have not setup git and GitHub yet, you can follow the steps to do so. For this lab and subsequent labs, you will be required to make Gradescope submissions via your GitHub repo. If you already have your environment configured to use GitHub, then you can skip these git configuration instructions.

3.1 Do some initial ONE-TIME git configurations (this step has to be done individually)

  • On separate machines, log onto your account.
  • In your ~/cs32 directory, type the following commands, replacing "Mehmet Emre" with your name and with your email address.
git config --global "Mehmet Emre"
git config --global ""
  • Next, generate a private/public key pair and upload your public key to your GitHub account. To do this refer to this tutorial: . In the process of setting up your key pair, when asked for a passphrase just press enter. By doing this step you will avoid having to enter a password or passphrase everytime you push your code to git.

3.2 Create a new private repo on the GitHub organization, add your partner as collaborator (if applicable)

  • Create a repo for this lab on the pilot's GitHub accoun: To do this, open a browser and navigate to Log into the pilot's GitHub account. From the drop down menu on the left, select our class organization: ucsb-cs32-s22 and proceed to create a new private repo. Follow this naming convention: if your GitHub username is mehmet and your partner's is ben, your should name your repo lab3_ben_mehmet (usernames appear in alphabetical order). Also remember that you must set the visibity of your repo to be PRIVATE when creating it.
  • If applicable, the pilot should add the navigator as a collaborator on GitHub. To do this navigate to the git repo you just created. Choose the settings tab. Then click on the 'Collaborators and teams' option on the left. Scroll all the way down and add the navigator's GitHub account. Then press on the 'Add collaborator' button. Now you and the navigator share the ownership of your git repo.

3.3 Clone the git repo to your local computer

  • On the terminal, change to your cs32 directory:
cd ~/cs32
  • Using the web-browser, navigate to your newly created repo on GitHub. Find the address of your git repo. Click on the green "clone or download button". If your git repo was named lab3_mehmet, then the git address should something like: "". Now clone your repo into your CSIL account by typing the following on the terminal, replacing the last argument with the address of your git repo.
git clone
  • Type ls to see your new git repo directory and change into that directory
cd lab3_mehmet

4 Copying the lab template

The code for the lab is in the following address:

You should see a listing of several C++ files. We are going to copy those into your lab3 repo's directory all at once with the following command:

cp ~emre/public_html/cs32/code/lab3/* ~/cs32/<your_lab3_directory>

You should now see several files in your directory—the same ones that you see if you visit the link above.

If so, you are ready to move on.

If you don't see those files, go back through the instructions and make sure you didn't miss a step. If you still have trouble, ask your TA / tutors for assistance.

Its now time to use the git-command line tools to perform version control for the files in your git repo. The four essential commands we will be using are:

# fetch (download) the most recent changes and update the current repository
git pull 
# add (mark) the current directory to the changes we are going to commit
git add .
# commit all the marked changes with the given commit message
git commit -m "Initial version of lab3 files"
# push committed changes to `main` branch (your repository may use `master` instead; check with the TAs/LAs if this command fails)
git push origin main 

Go ahead and type them out on a terminal in your git repo directory. The above commands save a snapshot of your code on GitHub. To check that this was done sucessfully open a web-browser and navigate to your repo on GitHub. Then check to see that the starter code appears in your repo.

Note: Every time you add a new piece of logic to your code, you should save a snapshot of the latest version of your code by issuing the commands: git add ... , git commit ... and git push .... All the previous versions will be available to you as well and you have the option of reverting to older versions (We will see how in later labs). As you go through the rest of this lab you will essentially need to use these commands to keep track of the different versions of your code. Note that you should only keep relevant files in your repo - avoid uploading non-important LARGE files in your repo since this may cause errors when making your submission to Gradescope.

Congratulations on integrating git into your workflow!

5 Getting the code to pass the tests

In this week's lab, you have the following files:

  • Makefile
  • student.h, student.cpp
  • studentRoll.h, studentRoll.cpp
  • tddFuncs.h, tddFuncs.cpp
  • testStudent00.cpp, etc.
  • testStudentRoll00.cpp, etc.

Your job is, as usual, get all the test cases to pass. This involves implementing the "Big Three": Copy Constructor, Overloaded Assignment Operator, and Destructor.

In addition to the regular test cases, there are also "leakTests". This involves running a utility called valgrind on your code to see whether there are any memory leaks, or other problems involving memory management (such as using objects after freeing them). You will only pass the tests if your code has proper memory management.

You will submit only the student.cpp and studentRoll.cpp files. As a result, there are two quite annoying things that you'll just have to put up with:

  • In the Student class, the name attribute is implemented with a C-string that is allocated with dynamic memory on the heap. This is annoying. You might prefer to use the std::string class. Of course you would. But, that's not the point of this assignment. The point of this assignment is to know whether you can manage memory properly.
  • In the StudentRoll class, the list of students is a linked list of structs rather than an std::list<Student> or std::vector<Student> or something. This is indeed annoying. Tough. We are training you for the situation where you don't have any choice, but have to work with the data structures you are given.

In certain later assignments, you will be given the freedom to choose whatever data structure or implementation is appropriate. You'll be able to decide whether to use std::string, or C-strings, whether to use array or std::vectors, etc. This is not one of those assignments.

6 Suggested way to proceed

I suggest proceeding in the following steps:

  1. Work on each test file for student, getting those tests to pass, i.e. testStudent00.cpp, testStudent01.cpp, etc.
  2. To get these to pass, you need to implement, possibly among other things, the Copy Constructor and Overloaded Assignment Operator for Student.
  3. Then, try to get the leak tests to pass as they pertain to Student, i.e.
  4. make lts00
  5. make lts01
  6. make lts02
  7. make lts03
  8. This will require implementing the destructor for Student
  9. Work on each test file for StudentRoll, getting those tests to pass, i.e. testStudentRoll00.cpp, testStudentRoll01.cpp, etc.
  10. To get these to pass, you need to implement, possibly among other things, the Copy Constructor and Overloaded Assignment Operator for StudentRoll
  11. Then, try to get the leak tests for StudentRoll to pass, i.e.
  12. make ltsr00
  13. make ltsr01
  14. make ltsr02
  15. This will require implementing the destructor for StudentRoll

6.1 How do I know if I'm done?

When you are done, you should be able to do both of the following, and see no error messages:

  • make tests
  • make leaktests

7 Submitting via Gradescope

The lab assignment "Lab 3" should appear in your Gradescope dashboard in CMPSC 32. If you haven't submitted anything for this assignment yet, Gradescope will prompt you to upload your files.

For this lab, you will need to upload your modified files (i.e. student.cpp and studentRoll.cpp). For this lab and subsequent labs, you are required to submit your files with your GitHub repo (if you haven't configured GitHub yet, please refer to the instructions at the beginning of this lab).

If you already submitted something on Gradescope, it will take you to their "Autograder Results" page. There is a "Resubmit" button on the bottom right that will allow you to update the files for your submission.

For this lab, if everything is correct, you'll see a successful submission passing all of the autograder tests.

Remember to add your partner to Groups Members for this submission on Gradescope if applicable. At this point, if you worked in a pair, it is a good idea for both partners to log into Gradescope and check if you can see the uploaded files for Lab 3.

Author: Mehmet Emre


The material for this class is based on Prof. Richert Wang's material for CS 32