CITS2002 Systems Programming  
 

Unit home

Project 1

help2002

Lecture & Workshop
recordings on LMS

Schedule

FAQ

Unit outline

C textbooks

OS textbooks

Information resources


Extra reading

Past projects

Recent feedback


Working effectively

Look after yourself!

Project 1 2012 - report Australian Football League statistics

Competitions in the Australian Football League (the AFL) consist of a number of teams which play weekly games against each other, for a fixed number of rounds. Teams score during each game by kicking a combination of goals and behinds; each goal is worth 6 behinds and, thus, a team's score of 10 goals and 8 behinds is equivalent to a total of 68 behinds.

The team winning each game earns 4 premiership points towards the overall competition ladder; in the event of a drawn game, both teams earn 2 points. Throughout the rounds, each team also maintains a percentage - the ratio of the total number of behinds scored by that team, to the total number of behinds scored by all teams playing in games against them.

At the end of all rounds, the team with the most premiership points or, in the event of multiple teams having the same number of premiership points, the team with the highest percentage, are deemed the minor premiers.

In 2012, the national AFL competition involved 18 teams and 22 rounds. Each team played every other team at least once and, obviously, some teams played each other twice. At the end of all rounds, (sadly) Hawthorn were the minor premiers, earning 68 premiership points by winning 17 of their 22 games. One other team also had 68 points, but Hawthorn's percentage of 154.59% was higher. See the final 2012 AFL Ladder from the official AFL website.

The GOAL of this project is to write an ISO-C99 program to produce a text file containing the final competition ladder after all rounds have been played.


Program requirements

  1. Your program must be named myafl.c

  2. Your program must accept three command-line arguments, which are the names of three text files:

    • an input file providing the teamnames - here is an example providing 8 teamnames.
      Each unique teamname will appear one-per-line. There will be at most 24 teamnames. Each teamname will have at most 30 characters; all characters will be alphabetic.

    • an input file providing the details and final scores from each game - here is an example providing the results of 8 teams playing 12 rounds.
      Each game's results appear one-per-line. Each result consists of 6 fields, separated by one or more SPACE characters. The fields are: the first team's name, the number of goals scored by the first team, the number of behinds scored by the first team, the second team's name, the number of goals scored by the second team, and the number of behinds scored by the second team. Both teams will score in every game. The team named first may be the winner, or the team named second may be the winner, or the game may be drawn. A blank line separates each round.

    • an output file containing the final ladder - here is an example providing the final ladder after 8 teams have played 12 rounds.
      The final ladder must consist of lines, one-per-team, containing 9 fields, separated by exactly one SPACE character. The fields for each team must be: the teamname, the number of games played, the number of games won, the number of games lost, the number of games drawn, the total number of behinds scored by (for) the team (all season), the total number of behinds scored against the team by other teams (all season), the team's percentage (reported to 2-decimal-points), and the number of premiership points.

      The ladder must be sorted, with the minor premiers at the top (the first line), and the lowest ranked team (the wooden spooners) at the bottom.

    A possible invocation of your project is:

    prompt> ./myafl teamnames results ladder

  3. Your program must check the validity of both input files (as described in the previous step). If an error is detected, your program should use printf() to print an error message, and then immediately call exit(EXIT_FAILURE).

  4. Your program must invoke the standard utility program  /usr/bin/sort  to sort the final ladder. Your program must use the library functions fork() and execv() (and possibly others) to invoke  /usr/bin/sort. Your program must not just call the system() function.
    Note that the command-line options supported by  /usr/bin/sort  on OS-X, Linux, and cygwin(Windows) are often different.

  5. Your program must employ sound programming practices, including the use of meaningful comments, well chosen identifier names, appropriate choice of basic data-structures and data-types, and appropriate choice of control-flow constructs.


Testing your project

While using OS-X in CSSE Lab 2.01, you may like to test your project solutions using the following instructions:

  • Running the command:

    prompt> /cslinux/examples/CITS1002/WWW/projects/aflseason 8 12

    will generate a random AFL season involving 8 teams playing over 12 rounds, and will create 3 files in your current directory:

    test-teamnames test-results test-ladder

  • Each time you run aflseason it will generate a different random season. You may generate a non-random (repeatable) season by providing a specific random seed as an argument:

    prompt> /cslinux/examples/CITS1002/WWW/projects/aflseason -s 1 10 18

  • You may use the standard Unix program diff to report the differences (if any) between your final ladder and the one generated by aflseason:

    prompt> /cslinux/examples/CITS1002/WWW/projects/aflseason -s 1 12 24 prompt> ./myafl test-teamnames test-results my-ladder prompt> diff my-ladder test-ladder

    If diff produces no output (on the screen), then your ladder and the test ladder are identical files.


Good luck!

Chris McDonald.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Presented by [email protected]