The purpose of this assignment is for students to become familiar with compiling, running, and testing programs in the Unix environment, using library routines, and the concept of generic programming. Students will be introduced to the languages of the course, C, C++, Java, and Perl, and will have a chance to review a fundamental algorithm, namely quicksort. Most of the coding for the assignment will simply involve writing main programs and either using library routines or code from class. See Lecture 4 for relevent material and code.
The assignment involves sorting strings. A main program will be written that reads strings, one per line, from standard input, and writes the same strings, in sorted order, to standard output. This interface is the same as the Unix sort filter, except that only one string per line is allowed and the options that sort supports are not included.
Sorting is a very common operation and is widely supported through
standard library routines for different languages. Rather than
reinventing the wheel, when sorting is required it is a good idea to use a
library routine. A good library routine must provide a good interface
(see chapter 4 of the text) and should support many different situations
(i.e. different types of elements that are to be sorted). Algorithms
that support different data types are called generic and programming to
support generic algorithms is called generic programming. Different
languages have different types of support for generic programming (e.g.
For each problem, you are to write a separate main program. All main programs should follow the same interface as indicated in the introduction.
You should use the quicksort code from class to sort the strings. This code was modified to sort an array of character arrays (see quicksort.c). See the lecture notes on C for how to read/write strings.
You may expect no more than 1,000,000 lines of input. You may further assume that each line has no more than 80 characters (careful here). Finally, strings (lines) will have no whitespace.
You will output the sorted list of strings, one per line, to stdout.
Place your solution in a directory called A2. Your directory should contain a file called README that describes all of the files in A2 and summarizes what you did. Make sure to indicate if any of the problems were not done or are not working.
For each problem, create a subdirectory called probi, where i is the problem number. In each directory create a file called main.ext, where ext is the appropriate extension for the language being used (c, cpp, java, pl), with your main program. Put a brief comment in each main program file indicating the author, what the program does, the date and platform info, and how to use the program. You should also create a makefile that builds the executable program (see here for some help). The executable program should be called sorti, where i is the problem number. The Java program will be called sort.class after it is compiled. The makefile from problem 6 will simply copy main.pl to sort6.pl, and give it execute permission.
Make sure you test each program. Include the file containing sample strings that you used to test your program. It will be in the parent directory, and called testInput .
Create a gzipped tar file containing a directory called A2 (use the command tar to do this) with your solutions. If you created a directory called A2 with all of the files for your assignment 2 solution, you can use the command:
$ tar -zcvf A2.tar.gz A2
to create the desired gzipped tar file (the convention is to use the .tar extension for tar files and the .gz extension for gzipped files). See man tar of info tar for more information about tar.
All assignments should be submitted using webct. You should submit your gzipped tar file.