CS202 Computer Science II
FAQ Newsboard  Telnet Email TA Lectures Assignments Man pages Help

Assignment 3
Due October 12th before 9:00 a.m. in class


Last modified 9/28/98
A Makefile and sample Test Cases for program verification and turnin intructions

This assignment will get you familiar with command line arguments, sorting, structs, and reinforce the idea of separating your code into many files both for modularity and for maintainability.

Design a Bubble Sort Program (sorting in ascending order) that takes upto two command line arguments and read, sorts, and prints student records. A student record is defined by the following structure in the file type.h

struct Student {
  int ssn;
  char name[STRINGLENGTH];
  float gpa;
};
STRINGLENGTH along with other definitions is in the file const.h.

You can expect the input to be in the form

ssn	name	gpa
and the file input gives you sample input for 10 students.

The program can be called in one of three (3) ways:

1.      srter 
2.	srter m
3.	srter m -[s/n/g]

An optional command line argument does NOT have to be present on the command line. If an optional argument is not present on the command line the program uses a default value.

  1. m, the first OPTIONAL argument identifies the size of the input. That is, it defines the number of student records to read, sort (using bubble sort), and print. For example:

  2. The second OPTIONAL argument specifies the sort field by which to sort the student records. The default is to to sort by the gpa field.

As you can see, you should be able to run your program in a variety of ways from the command line.

Here are some constraints on the assignment:

  1. You should put your struct declaration(s) in the file type.h and your program in as3.cpp

  2. You may assume that if there is one command line argument it must be the number of records to sort and you sort by gpa. If there are two command line arguments then the first determines the number of records to sort and the second defines the sort field.
  3. You may use the string library function strcmp() to compare two strings. Follow the link to read the manual page and learn how to use strcmp().
  4. NO global variables.
  5. You must use a one-dimensional array of the structs defined in type.h
  6. You may assume that you will never have to deal with more than 75 records at a time (CS202's enrollment cap is actually 60).
  7. You must define and use a swap() function that passes structures by reference to swap items in your array of structs.
  8. Your main program as3.cpp looks like:
    		#include "const.h"
    		#include "type.h"
    		.
    		.
    		.
                    int main(int argc, char * argv[])
                    {
                      ...declarations...
                      ...
                      ProcessCommandLine(......);
                      ReadInput(.......);
                      BubbleSort(.......);
                      PrintOutput(.......);
                      return 0;
                    }
            
    I expect you to define and use at least the four functions listed above (as well as swap).
  9. I also expect (the Makefile also expects this): Any deviations will cost you points.

Good Luck. Start on the assignment now.


Examples

Using the file input as an input file to the program, here are some examples. Please follow these instructions for turning in assignments.