lab08 : Exceptions and Template Classes

num ready? description assigned due
lab08 true Exceptions and Template Classes Thu 03/05 08:00AM Wed 03/11 11:59PM

Goals

Step by Step

Step 0: 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.

As stated in previous labs, there are a few requirements you must follow if you decide to work with a partner. I will re-iterate them here:

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

Step 1: Get the lab08 starter code into your repository directory

In this step, we are going to copy the lab08 starter files from the instructor’s directory into your /cs32/lab08 directory.

The files are in the instructors directory at

~richert/public_html/cs32/misc/lab08/*

and also accessible via the URL

http://cs.ucsb.edu/~richert/cs32/misc/lab08/

You want to copy these files into your ~/cs32/lab08 directory.

Step 2: Implement the SimpleList.cpp functionality.

A few notes about this specific implementation (as described in SimpleList.h):

A few notes about throwing Exceptions:

Your implementation will need to implement the following functions, and throw Exceptions in certain cases:

template <class T>

Another note on checking if a template type is a pointer:

template<class T>
void destroy(T element) {
	// do nothing
}

template <class T>
void destroy(T* element) {
	// delete the pointer type
	delete element;
}

template <class T>
void function1(vector<T> x) {
	if (is_pointer<T>::value) {
		//delete x[0]; // may not compile even if T is a pointer type

		// Will call destroy(T* element)
		destroy(x[0]);
	} else {
		// will call destroy(T element)
		destroy(x[0]);
	}
}

int main() {
	vector<int*> x;
	int* y = new int;
	x.push_back(y);
	function1(x);
	return 0;
}

Step 3: Testing

The following executables will be generated by typing make all:

You can test each executable separately by executing each individual binary file or you can run all tests by typing make tests.

There will also be a memory test for testSimpleList3 that will check for memory leaks. This will use testSimpleList3 to see if your code is deallocating memory properly. You can run this memory test after testSimpleList3 is compiled with:

make lt01

Step 4: Submitting via Gradescope

You will turn in SimpleList.cpp for this lab.

The lab assignment “Lab08” 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 file (i.e. SimpleList.cpp). For this lab, you are required to submit your files with your github repo.

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 Lab08.