CS 14 - Lab
CS 14
Homepage
Templatized Insertion Sort
You will be writing a templatized version of the insertion sort
sort algorithm.
You will then use your sorting function to sort arrays of ints, floats,
chars, and a user defined class (obtainable here).
The user defined class will consist of
a first name and a last name string. Instances of the class will be sorted
by last name and then by first name. You will need to overload one or more
operators to accomplish the sorting of the class instances.
You will also need the print functions obtainable in
print.cc. Please note that I could have used a template function instead
of giving you 4 different instances of the print function, one for each
type sorted. .5 extra credit points will be available for replacing the print
function with a templatized print function and implementing any necessary
overloaded functions to acheive this.
Note about template functions and g++
To comply with good coding style, you should assume that when creating your
template functions, they should go in a separate file other that where
your main function is in main.cc. However, due to the implementation of
gcc/g++, template functions must appear in the file that has the function
call to those functions. This is not the norm, just happens to be
how gcc/g++ was implemented. You will find that different compilers
will not have this problem. If you had a template class with template
functions,
those could all go in a header file. However, since you are just writing
template functions, don't put them in a header file. Instead, you may put
your templatized function(s) before the main function in my main.cc file.
The TA will then have to visually check the main function to verify
that you have not altered the functionality testing.
Point Breakdown For Lab Assignment
Please show the output
from main.cc to the TA if.
The TA will also
look at your code for correctness when checking out.
Remember, to
receive credit for this lab, you MUST turn the code in online as well
as demo in lab, however, you will only receive points for what you demo
to the TA during lab section. If you do not turn in your code online,
you will lose points for your lab. All code must be turned in online for
archival purposes. Remember to put both partners names on the code that you
turn in.
Remeber to compile your code using the flags "-g -Wall -W -Werror -pedantic".
You must use a makefile.
- 2 points - Attendance - Lab attendance will be 20% of the grade for each
lab. You will receive 1 point when the lab begins and 1 point when the lab
ends. Attendance will be taken during the first and last 5 minutes of the
lab period
- 6 point - Correctly sorting ints, doubles, and chars using one templatized
insertion sort function
- 2 point - Correctly sorting the Name class instances using the same
templatized insertion sort function used for ints, doubles, and chars.
- Deductions:
- -1 point - If both partners turn in the code. There should
only one turnin per group
- -1 point - not logically seperating your code into seperate files.
It is okay to put your template functions in the main.cc file.
- -1 point - no makefile
- -5 points - Turned into the wrong lab section.
- -1 point - No name on work turned in
- -5 points - Code not turned in at all. This deduction also applies to
turnins that do not contain a the partners name (only the name that is not
on the turnin will have 5 points deducted. The person that actually turned
the code in will only have 1 point deducted if their name is not on the
turnin).
- -5 points - If your currently assigned partner is in lab and you do not
work together.
- -1 point - If your code seg faults at any time.
- +.5 Extra Credit - Templatizing the print function to work for
ints, chars, doubles, and Name class instances.