CITS2002 Systems Programming  
prev
next CITS2002 CITS2002 schedule  

Identifying related data

Let's consider the 2012 1st project for CITS1002.

The goal of the project was to manage the statistics of AFL teams throughout the season, calculating their positions on the premiership ladder at the end of each week.

Let's consider the significant global variables in its sample solution:


//  DEFINE THE LIMITS ON PROGRAM'S DATA-STRUCTURES
#define MAX_TEAMS               24
#define MAX_TEAMNAME_LEN        30
....

//  DEFINE A 2-DIMENSIONAL ARRAY HOLDING OUR UNIQUE TEAMNAMES
char    teamname[MAX_TEAMS][MAX_TEAMNAME_LEN+1];        // +1 for null-byte

//  STATISTICS FOR EACH TEAM, INDEXED BY EACH TEAM'S 'TEAM NUMBER'
int     played  [MAX_TEAMS];
int     won     [MAX_TEAMS];
int     lost    [MAX_TEAMS];
int     drawn   [MAX_TEAMS];
int     bfor    [MAX_TEAMS];
int     bagainst[MAX_TEAMS];
int     points  [MAX_TEAMS];
....

//  PRINT EACH TEAM'S RESULTS, ONE-PER-LINE, IN NO SPECIFIC ORDER
    for(int t=0 ; t<nteams ; ++t) {
        printf("%s %i %i %i %i %i %i %.2f %i\n", // %age to 2 decimal-places
                teamname[t],
                played[t], won[t], lost[t], drawn[t],
                bfor[t], bagainst[t],
                (100.0 * bfor[t] / bagainst[t]),      // calculate percentage
                points[t]);
    }

It's clear that the variables are all strongly related, but that we're naming and accessing them as if they are independent.

 


CITS2002 Systems Programming, Lecture 5, p10, 5th August 2024.