COMS W3101-2
Homework 4: Templates, Separate Compilation, Debugging
Worth: 20% of total homework grade.
Goals:
The goal of this homework is to give you experience templating functions, making a multi-file project, and using some preprocessor features.
Assignment:
-
hw4a.cc
(25%)
Write a template function that takes a vector reference and reverses the order of elements in the vector. The function must be templated to use any type of vector (i.e. vector<double>, vector<string>, etc.)
To test your template write a main method which takes a sequence of string input until EOF is received and then prints the sequence in reverse to the screen.
e.g. on input:
one
two
blue
the output should be:
blue
two
one
-
hw4b
(50%)
Using hw3c.cc as your starting point, write the functions necessary to allow an inputted list of email headers to be sorted by: From or Date.
This will require an input loop, that should stop when EOF is received (see hw2 for review).
Put your email header class and member functions in a file named emailHeader.cc
Put any other functions in a file named helper.cc
Lastly, put the code to to accept a series of email headers and then print them 2 times (first sorted by From, then sorted by Date, etc.) in a file named main.cc
Write a makefile that will compile your project (as shown in class).
All of these files and any header (.h) files should be placed in a directory named hw4b
-
hw4c.cc
(25%)
Re-write hw3b.cc using macro features in place of the exceptions.
Instead of throwing and catching an exception your code should handle the error conditions by printing out an error message that gives the file and line on which the error occured.
Error messages should be printed out unless the NDEBUG flag is used in compilation (a mistake was made explaining this in lecture, please look at the session code to see proper usage).
-
hw4CHALLENGE.cc
Replace all of the functions (except main) in hw4c.cc with macros.
Files to be submitted:
- hw4a.cc
- hw4b (contents specified in description, make certain to copy the entire directory not just the files - e.g. cp -r hw4b submit)
- hw4c.cc
- optionally hw4CHALLENGE.cc
- typescript
- REAMDE
Remember, all source code files should be clearly commented.
Code should be clean and easily readable.
Errors should be checked or handled according to your current knowledge-base.
If your files are not named according the above conventions, they will not be graded and you will receieve NO CREDIT.
For README and typescript requirements, look in the "How To" section.
How To:
Make your submission
Write a README
Make a typescript
Use CUNIX
Joshua Reich reich@cs.columbia.edu
Last Modified: June 12th, 2006