| FAQ | Newsboard | Telnet | Email TA | Lectures | Assignments | Man pages | Help |
|---|
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 gpaand 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.
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:
#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).
Good Luck. Start on the assignment now.
% srter < input 1212 bab 1 3423 gag 2.45 4321 bibi 2.76 5555 ggg 2.87 3294 onds 2.93 8888 bbb 3.12 1111 aaa 3.45 1234 didi 3.76 923 jfid 3.82 2222 abb 4
% srter 6 < input 1212 bab 1 3423 gag 2.45 5555 ggg 2.87 8888 bbb 3.12 1111 aaa 3.45 2222 abb 4
% srter 8 -n < input 1111 aaa 3.45 2222 abb 4 1212 bab 1 8888 bbb 3.12 4321 bibi 2.76 1234 didi 3.76 3423 gag 2.45 5555 ggg 2.87
% srter 9 -s < input 923 jfid 3.82 1111 aaa 3.45 1212 bab 1 1234 didi 3.76 2222 abb 4 3423 gag 2.45 4321 bibi 2.76 5555 ggg 2.87 8888 bbb 3.12