Exercise 31
Info

This is an in-class exercise. An exercise page like this one will contain a brief description but is intended to be supplemented by discussion during our meeting time. Complete the exercise to the best of your ability in the time given. Feel free to talk with other students as you work, and do not be afraid to ask questions if you get stuck. Aim to complete as much as possible during our meeting. You are encouraged to work at home to complete what you do not get through today, and ask questions over Piazza or in office hours.

Learning Objectives

Reinforces concepts learned in today meeting:

  • writing template classes

Part 1

Pull the starter code for this exercise from the public repo by taking the following steps:

  1. Log into ugrad, navigate into our public repo, then type git pull to synchronize your local repo and working copy with the remote repo.

  2. Copy the files from the public class repository /exercises/ex31/ directory to your personal repo. Navigate to your personal repo copy – you should see files named Makefile, README, and main1.cpp inside. We will also make directory ex30-sol available the morning of this exercise.

Part 2

Read main1.cpp. It shows an example of how to use a new template class named my_set. Before you can compile and run the code using commands make and ./main1, you will need to transform your completed files int_node.h, int_set.h and int_set.cpp from Exercise 30. If you didn't complete Exercise 30 yet, use the files provided in the ex30-sol folder as a starting point for this exercise.

If using your own solution files Exercise 30, copy them over to your Exercise 31 folder. This will serve as the remainder of your starter code for Exercise 31.

Part 3

Next, follow the instructional comments in README.

Part 4

Run valgrind on main1.cpp. Fix any memory leaks that it finds.

Part 5

Add additional testing code in main1.cpp to more fully test your code, then re-run valgrind.