CS 246 Homework 4:  Modularity and Program Design

You MUST work with one other person on this assignment.

Full Assignment Due:   Monday, March 25, 2013
 
Please read the homework guidelines before you proceed.


Project Description

This assignment is simple:  redo your Homework 3 project, improving the modularity of your program while adding several new features.  In addition to the new features, any aspect of your Homework 3 submission that did not work should be fixed.

Rewrite [40pts]

Rewrite your Homework 3 so that it is as modular, efficient and readable as you can possibily make it. Reorganize your data structure if necessary.

Address the following in you revision and write-up:

Create a write-up reporting on what changes you made and why.


New Features

Command-line Arguments [20pts]

Make the filenames optional in the command line arguments.  If no arguments are given for the file names, default to all 21 input files.

Add the flag --help, which prints out a Unix-like manual page informing the user how to use your program and its arguments. Also print this screen whenever improper input has been detected. Also, if there is a --help flag, it cancels out all others, i.e. help screen will be printed and nothing else.

Change the -m/-f flags to use a single -s names, so that your program will print the statistics for the given name (or names, separated by commas). Note that we're no longer specifying male/female, so your program should figure that out itself (if a given name appears in both lists, then display the stats for both male and female versions of the name).  For example:

hw4 -s John,Jennifer names1900 names2000

will print out the rank, number and percentages of the names John and Jennifer used in 1900, 2000, as well as the combined total stats of these two years.

Add the flag -r names, which prints out the rank of the names searched (and total rank)

Add the flag -n names, which prints out the usage number of the names searched (and total usage number)

Add the flag -p names, which prints out the percentage of the names searched (and total percentage)

These 3 flags can combine at will and come in any order, i.e. -r -n -p is equivalent to -n -p -r, or -npr or -nrp, etc. Note that the -s flag is equivalent to -npr. At least one flag is required.

You may assume that the list of file names is always last, i.e. the first non-flag argument you encounter is assumed to be the beginning of the list of file names. However, the flags themselves may come in any order. If --help is present, ignore all others.

Make sure you error-check your arguments thoroughly, i.e. illegal/badly-formated options, non-existent options. Remember that some flags are optional and some flags (--help) cancel out all others, and the order of flags should not matter. Your program should behave rationally no matter how unreasonable the input or the value of flags. Check out Unix utility programs to see examples of flag and error handling.

The unix wild star (*) will let you specify multiple file names that fit a certain pattern easily, for example:

hw4 -s Eric names200*

will be expanded to:

hw4 -s Eric names2000 names2001 names2002 names2003 names2004 names2005 names2006 names2007 names2008 names2009

by the shell for you. Using this feature to test might reduce tedious typing.

Substrings [20pts]

Continuing from the previous part, implement a further functionality so that your program is able to find all variations of a name and print the proper stats. For example, given "John", there are "Johnnie", "Johnathan", etc. Note that I am only asking for strict substring variations, not the smart variations such as recognizing Bill is short for William. However, do note that there are male and female variations, such as "Johnna" for "John".

For each variation, print out the proper stats as dictated by the flags and input files as before.

Implement the flag -v name for this. -v overwrites -s, if both were given.

Sorting [20pts]

Instead of using any built-in sorting routines, write your own QuickSort implementation and use it to do all of the sorting required in this project.


Final Program

Submit one assignment for all partners, following the assignment guidelines and submission instructions. 

Be sure to list all partners' names in your README file. 

Provide a working Makefile for your assignment.  The Makefile should support three commands:  make, make run, and make clean.  I must be able to:

  1. Uncompress your submission
  2. "cd" into the directory
  3. Type "make" and have your program compile itself.
  4. Type "make run" and have it output the results of the following commands:
    1. hw4 --help
    2. hw4 -rp John,Jennifer,Eric,Sam,Susan,Katherine,Catherine
    3. hw4 -v John,Jen,Eric,Sam,Susan,Kat,Cat

Put all source code, the data files, the README, your writeup, and Makefile into a single .tar.gz file.

Additionally, each partner should also submit an independent and private brief statement via e-mail to Eric that describes each partner's contribution to the project.  Use the subject "CS246 HW4 Partner Work Distribution".